#serde #lua #value #de #rlua

rlua_serde

Serde (De)serializer implementation for rlua Value

5 releases (3 breaking)

Uses old Rust 2015

0.4.0 Jan 31, 2020
0.3.1 Apr 26, 2019
0.3.0 Feb 8, 2019
0.2.0 Oct 11, 2018
0.1.0 Feb 13, 2018

#1786 in Encoding

Download history 6/week @ 2024-08-26 25/week @ 2024-09-23 28/week @ 2024-09-30

118 downloads per month
Used in 2 crates

MIT license

30KB
761 lines

rlue_serde

Implementation of serde Serializer/Deserializer for rlua::Value

License: MIT Crates.io Documentation

More information about this crate can be found in the crate documentation.

Usage

To use rlua_serde, first add this to your Cargo.toml:

[dependencies]
rlua_serde = "0.4"

Next, you can use to_value/from_value functions to serialize/deserialize:

#[derive(Serialize, Deserialize)]
struct Foo {
    bar: u32,
    baz: Vec<String>,
}

fn main() {
    let lua = rlua::Lua::new();
    lua.context(|lua| {
        let foo = Foo {
            bar: 42,
            baz: vec![String::from("fizz"), String::from("buzz")],
        };

        let value = rlua_serde::to_value(lua, &foo).unwrap();
        lua.globals().set("value", value).unwrap();
        lua.load(
            r#"
                assert(value["bar"] == 42)
                assert(value["baz"][2] == "buzz")
            "#).exec().unwrap();
    });
}

Dependencies

~0.8–1.3MB
~23K SLoC