#explicit #deserialize #structs #fork #tuple #traits #serde

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

#674 in Encoding

Download history 130/week @ 2025-01-01 20/week @ 2025-01-08

150 downloads per month

MIT license

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