Crates.io | serde-tagged-intermediate |
lib.rs | serde-tagged-intermediate |
version | |
source | src |
created_at | 2022-05-08 01:15:03.987989 |
updated_at | 2024-12-07 14:06:33.271545 |
description | Tagged intermediate representation for Serde serialization |
homepage | https://github.com/PsichiX/serde-tagged-intermediate |
repository | https://github.com/PsichiX/serde-tagged-intermediate |
max_upload_size | |
id | 582321 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Intermediate representation for Rust's Serde serialization
This crate was made to solve these particular problems:
Provide untyped (obviously "fat") runtime value representation used as exchange data ready to be deserialized on demand into typed data, for data where serializable tagged trait objects don't work on taret platforms.
Example: data stored in interpreted language runtime value.
Support for more interpreted than exact data conversion (if it quacks like a duck, treat it like a duck) which is default behavior, optionally force to read exact layout stored in value.
Example: more forgiving convertion between unrelated data formats.
Support for versioning (allow to produce diffs between two versions of data, that can be later patched on demand).
Example: Game assets content difference for DLC or any episodic content usage; editor UI sending only changes to the game runtime to patch what actually changed in the world (instead of sending entire serialized object state).
Support for tagged intermediate data.
Example: Game asset stores data of type that is decided at runtime (associated tag gives hint what type its layout represents).
Core crate with most important Intermediate
and ReflectIntermediate
types:
[dependencies]
serde-intermediate = "*"
If you prefer to compile without ReflectIntermediate
derive macro (derive
feature adds derive macros and is enabled by default):
[dependencies]
serde-intermediate = { version = "*", default-features = false }
Crate that adds support for tagged intermediate value (to embed tagged Intermediate
in other serializable data with TaggedIntermediate
type):
[dependencies]
serde-tagged-intermediate = "*"
Same as with core crate, you can exclude ReflectIntermediate
from compilation:
[dependencies]
serde-tagged-intermediate = { version = "*", default-features = false }
Serialize/deserialize:
use std::time::SystemTime;
use serde::{Serialize, Deserialize};
#[derive(Debug, PartialEq, Serialize, Deserialize)]
enum Login {
Email(String),
SocialMedia{
service: String,
token: String,
last_login: Option<SystemTime>,
}
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Person {
// (first name, last name)
name: (String, String),
age: usize,
login: Login,
}
let data = Person {
name: ("John".to_owned(), "Smith".to_owned()),
age: 40,
login: Login::Email("john.smith@gmail.com".to_owned()),
};
let serialized = serde_intermediate::to_intermediate(&data).unwrap();
let deserialized = serde_intermediate::from_intermediate(&serialized).unwrap();
assert_eq!(data, deserialized);
More elaborate problems and solutions:
License: MIT OR Apache-2.0