| Crates.io | serde_inner_serialize |
| lib.rs | serde_inner_serialize |
| version | 0.1.1 |
| created_at | 2024-12-28 02:29:03.118146+00 |
| updated_at | 2024-12-28 02:29:03.118146+00 |
| description | A package of proc macros to assist in serializing nested structures flatly via serde |
| homepage | |
| repository | https://github.com/dave-gray101/serde-inner-serialize |
| max_upload_size | |
| id | 1496824 |
| size | 17,031 |
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