Serde support for mlua
Go to file
zrkn 8060f24cb8 Update readme 2019-04-26 13:24:48 +03:00
src fix typo 2019-04-24 07:25:46 +02:00
.gitignore Initial commit 2018-02-13 15:12:22 +03:00
Cargo.toml Version 0.3.0 release 2019-02-08 14:44:10 +03:00
LICENSE Add LICENSE file 2018-10-11 15:50:10 +03:00
README.md Update readme 2019-04-26 13:24:48 +03:00

README.md

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 eventd, first add this to your Cargo.toml:

[dependencies]
rlua_serde = "0.3"

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();
    });
}