#deserialize-tuple #tuple #struct #value #i32 #serde-tuple-explicit

serde_tuple_explicit

A fork of the serde_tuple crate using explicit traits to de/serialize structs

1 stable release

1.1.0 Jan 3, 2025

#1927 in Encoding

MIT license

16KB
388 lines

Derive macros to serialize and deserialize a struct with named fields as an array of values

Examples

use serde_tuple_explicit::*;

#[derive(SerializeTuple, DeserializeTuple)]
pub struct Foo<'a> {
    bar: &'a str,
    baz: i32
}
let foo = Foo { bar: "Yes", baz: 22 };
let json = {
  let mut buf = vec![];
  let mut serializer = serde_json::Serializer::pretty(&mut buf);
  foo.serialize_tuple(&mut serializer).unwrap();

  unsafe { String::from_utf8_unchecked(buf) }
};
println!("{}", &json);
// # => ["Yes",22]

serde_tuple_explicit

A fork of the serde_tuple crate using explicit traits to de/serialize structs.

Usage

use serde_tuple_explicit::*;

#[derive(SerializeTuple, DeserializeTuple)]
pub struct Foo<'a> {
    bar: &'a str,
    baz: i32
}

let foo = Foo { bar: "Yes", baz: 22 };

let json = {
  let mut buf = vec![];
  let mut serializer = serde_json::Serializer::pretty(&mut buf);
  foo.serialize_tuple(&mut serializer).unwrap();

  unsafe { String::from_utf8_unchecked(buf) }
};

println!("{}", &json);
// # => ["Yes",22]

License: MIT

Dependencies

~2MB
~43K SLoC