1 stable release
1.1.0 | Jan 3, 2025 |
---|
#674 in Encoding
150 downloads per month
16KB
388 lines
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
lib.rs
:
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]
Dependencies
~2MB
~43K SLoC