Implementation of serde Serializer/Deserializer for rlua::Value
More information about this crate can be found in the crate documentation.
To use rlua_serde
, first add this to your Cargo.toml
:
toml
[dependencies]
rlua_serde = "0.4"
Next, you can use to_value
/from_value
functions to serialize/deserialize:
```rust
struct Foo {
bar: u32,
baz: Vec
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();
});
} ```