serde_inner_serialize

Crates.ioserde_inner_serialize
lib.rsserde_inner_serialize
version0.1.1
created_at2024-12-28 02:29:03.118146+00
updated_at2024-12-28 02:29:03.118146+00
descriptionA package of proc macros to assist in serializing nested structures flatly via serde
homepage
repositoryhttps://github.com/dave-gray101/serde-inner-serialize
max_upload_size
id1496824
size17,031
Dave (dave-gray101)

documentation

README

serde_inner_serialize macro crate

Helper for custom Serializers

This library is designed to add some helper methods to a struct making it easier to manually serialize its fields.

pub trait InnerSerializableTrait {
    const TYPE_NAME: &'static str;
    fn count_fields() -> usize;
    fn inner_serialize<S>(&self, state: &mut S) -> Result<(), S::Error>
    where
        S: serde::ser::SerializeStruct;
}

pub trait OuterSerializableTrait<T> where T: InnerSerializableTrait {
    const TYPE_NAME: &'static str;

    fn get_full_type_name(&self) -> &'static str;
}

By deriving from InnerSerializable and OuterSerializable these traits and their implementation can be added to your custom structures, making it easy to represent "alternative versions" of a structure that add additional fields (or computed values that must be serialized) while retaining a "flat" output.

For an example of how to use these types in practice, see this example file

The structure of this repo is based on the guidelines found within https://towardsdatascience.com/nine-rules-for-creating-procedural-macros-in-rust-595aa476a7ff

Commit count: 16

cargo fmt