Serde support for mlua
Go to file
zrkn 0df32c7456
Merge pull request #7 from clouds56/patch-1
upgrade rlua to 0.17
2020-01-31 03:13:44 +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 upgrade rlua to 0.17 2020-01-17 17:05:34 +08:00
LICENSE Add LICENSE file 2018-10-11 15:50:10 +03:00
README.md Bump version 2019-04-26 13:27:36 +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 rlua_serde, 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();
    });
}