serde-intermediate

serde-intermediate

Intermediate representation for Rust's Serde serialization


Table of contents

  1. Goals
  2. Installation
  3. Examples

Goals

This crate was made to solve these particular problems:


Installation

  1. Core crate with most important Intermediate and ReflectIntermediate types:

    toml [dependencies] serde-intermediate = "*"

    If you prefer to compile without ReflectIntermediate derive macro (derive feature adds derive macros and is enabled by default):

    toml [dependencies] serde-intermediate = { version = "*", default-features = false }

  2. Crate that adds support for tagged intermediate value (to embed tagged Intermediate in other serializable data with TaggedIntermediate type):

    toml [dependencies] serde-tagged-intermediate = "*"

    Same as with core crate, you can exclude ReflectIntermediate from compilation:

    toml [dependencies] serde-tagged-intermediate = { version = "*", default-features = false }


Examples

Serialize/deserialize:

```rust 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, } }

[derive(Debug, PartialEq, Serialize, Deserialize)]

struct Person { // (first name, last name) name: (String, String), age: usize, login: Login, }

let data = Person { name: ("John".toowned(), "Smith".toowned()), age: 40, login: Login::Email("john.smith@gmail.com".toowned()), }; let serialized = serdeintermediate::tointermediate(&data).unwrap(); let deserialized = serdeintermediate::fromintermediate(&serialized).unwrap(); asserteq!(data, deserialized); ```

More elaborate problems and solutions:

  1. Versioning (diff/patch) (test_versioning)
  2. Conversion between data layouts (test_transform)
  3. DLC / episodic content (test_dlcs)
  4. Data change communication between game and editor (testeditorcommunication)

License: MIT OR Apache-2.0