rlua_serde

Crates.iorlua_serde
lib.rsrlua_serde
version0.4.0
sourcesrc
created_at2018-02-13 13:10:49.406301
updated_at2020-01-31 00:19:35.265787
descriptionSerde (De)serializer implementation for rlua Value
homepage
repositoryhttps://github.com/zrkn/rlua_serde/
max_upload_size
id50988
size30,575
(zrkn)

documentation

README

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();
    });
}
Commit count: 25

cargo fmt