Serde support for mlua
Go to file
Cadey Ratio 9d12a4fc4b fix build 2020-07-05 20:50:33 -04:00
src fix build 2020-07-05 20:50:33 -04:00
.envrc fix build 2020-07-05 20:50:33 -04:00
.gitignore Initial commit 2018-02-13 15:12:22 +03:00
Cargo.toml fix build 2020-07-05 20:50:33 -04:00
LICENSE Add LICENSE file 2018-10-11 15:50:10 +03:00
README.md Bump version 2020-01-31 03:19:10 +03:00
shell.nix fix build 2020-07-05 20:50:33 -04: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.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();
    });
}