#deserialize #serialization #parser #config

macro esyn-derive

De/Serialization Rust In Rust

14 releases (8 breaking)

new 0.9.0 Apr 8, 2024
0.8.2 Jan 5, 2024
0.8.1 Dec 30, 2023
0.8.0 Nov 17, 2023
0.4.1 Jun 13, 2023

#46 in #de-serialization

Download history 35/week @ 2023-12-25 17/week @ 2024-01-01 31/week @ 2024-02-19 27/week @ 2024-02-26 2/week @ 2024-03-11 285/week @ 2024-04-01

287 downloads per month
Used in esyn

MIT/Apache

35KB
920 lines

[WIP] esyn

github crates.io docs.rs build status

De/Serialization Rust In Rust

Example

fn main() {
    use esyn::*;

    #[derive(Debug, PartialEq, EsynDe, EsynSer)]
    struct Test {
        _string: String,
        _vec_u32: Vec<u32>,
        _opt_i64: Option<i64>,
    }

    let expect = Test {
        _string: "hello".to_string(),
        _vec_u32: vec![1, 2, 4],
        _opt_i64: Some(-9223372036854775807),
    };
    let config = r#"
fn main() {
    let test = Test {
        _string: "hello",
        _vec_u32: [1, 2, 4],
    };

    test._opt_i64 = Some(-9223372036854775807);
}
"#;

    let test = EsynBuilder::new()
        .set_fn("main")
        .set_let("test")
        .get_once::<Test>(config)
        .unwrap();

    assert_eq!(test.get_ref(), &expect);

    // Serialization
    let code = quote! {
        fn main() {
            let test = #test;
        }
    }
    .into_pretty()
    .unwrap();

    println!("{code}");
}

For more examples take a look on tests.

Features

Suffix Syntax

fn main() {
    // ...

    config.val = 123;
}

Custom Syntax

// ...

#[derive(Debug, EsynDe, EsynSer, Default)]
#[custom_syntax]
struct Test {
    val: u8,
}

impl CustomSyntax for Test {
    // ...
}

// in config:
//
// fn main() {
//     let test = m!(123);
// }

// ...

see full example on struct_custom_syntax

Supported Types

u8 u16 u32 u64 u128 usize
i8 i16 i32 i64 i128 isize
f32 f64
bool
char String

Vec<T>
Option<T>
Box<T>

Struct
Enum
Tuple

see more

Dependencies

~330–780KB
~19K SLoC