diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2021-04-27 10:04:18 +0100 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2021-04-27 10:04:18 +0100 |
commit | f5b88624cedc119f50718cfda53b9de313a97f8f (patch) | |
tree | 9785c338fbfb4653e0ddcf47adf790f79e64081a /src | |
parent | 2fae94586dc83440409f0c7c3a9247fa576dff20 (diff) | |
download | mlua-f5b88624cedc119f50718cfda53b9de313a97f8f.zip |
Hide Deserializer inner fields
Improve documentation
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/prelude.rs | 1 | ||||
-rw-r--r-- | src/serde/de.rs | 9 | ||||
-rw-r--r-- | src/serde/mod.rs | 8 | ||||
-rw-r--r-- | src/serde/ser.rs | 18 |
5 files changed, 28 insertions, 9 deletions
@@ -118,6 +118,7 @@ pub use crate::value::{FromLua, FromLuaMulti, MultiValue, Nil, ToLua, ToLuaMulti pub use crate::thread::AsyncThread; #[cfg(feature = "serialize")] +#[doc(inline)] pub use crate::serde::{ser::Options as SerializeOptions, LuaSerdeExt}; pub mod prelude; diff --git a/src/prelude.rs b/src/prelude.rs index 6dfb0fe..b043ac6 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -16,4 +16,5 @@ pub use crate::{ pub use crate::AsyncThread as LuaAsyncThread; #[cfg(feature = "serialize")] +#[doc(inline)] pub use crate::{LuaSerdeExt, SerializeOptions as LuaSerializeOptions}; diff --git a/src/serde/de.rs b/src/serde/de.rs index 0da0b20..fe7ca38 100644 --- a/src/serde/de.rs +++ b/src/serde/de.rs @@ -7,7 +7,14 @@ use crate::table::{TablePairs, TableSequence}; use crate::value::Value; /// A struct for deserializing Lua values into Rust values. -pub struct Deserializer<'lua>(pub Value<'lua>); +pub struct Deserializer<'lua>(Value<'lua>); + +impl<'lua> Deserializer<'lua> { + /// Creates a new Lua Deserializer for the `Value`. + pub fn new(value: Value<'lua>) -> Self { + Deserializer(value) + } +} impl<'lua, 'de> serde::Deserializer<'de> for Deserializer<'lua> { type Error = Error; diff --git a/src/serde/mod.rs b/src/serde/mod.rs index 7562d51..c0a89ea 100644 --- a/src/serde/mod.rs +++ b/src/serde/mod.rs @@ -13,6 +13,7 @@ use crate::types::LightUserData; use crate::util::{assert_stack, StackGuard}; use crate::value::Value; +/// Trait for serializing/deserializing Lua values using Serde. pub trait LuaSerdeExt<'lua> { /// A special value (lightuserdata) to encode/decode optional (none) values. /// @@ -195,7 +196,7 @@ impl<'lua> LuaSerdeExt<'lua> for Lua { where T: Deserialize<'lua>, { - T::deserialize(de::Deserializer(value)) + T::deserialize(de::Deserializer::new(value)) } } @@ -221,3 +222,8 @@ static ARRAY_METATABLE_REGISTRY_KEY: u8 = 0; pub mod de; pub mod ser; + +#[doc(inline)] +pub use de::Deserializer; +#[doc(inline)] +pub use ser::Serializer; diff --git a/src/serde/ser.rs b/src/serde/ser.rs index 0278bc9..d919f1d 100644 --- a/src/serde/ser.rs +++ b/src/serde/ser.rs @@ -26,7 +26,7 @@ pub struct Options { /// /// Default: true /// - /// [`array_metatable`]: trait.LuaSerdeExt.html#tymethod.array_metatable + /// [`array_metatable`]: ../trait.LuaSerdeExt.html#tymethod.array_metatable pub set_array_metatable: bool, /// If true, serialize `None` (part of `Option` type) to [`null`]. @@ -34,8 +34,8 @@ pub struct Options { /// /// Default: true /// - /// [`null`]: trait.LuaSerdeExt.html#tymethod.null - /// [`Nil`]: ../enum.Value.html#variant.Nil + /// [`null`]: ../trait.LuaSerdeExt.html#tymethod.null + /// [`Nil`]: ../../enum.Value.html#variant.Nil pub serialize_none_to_null: bool, /// If true, serialize `Unit` (type of `()` in Rust) and Unit structs to [`null`]. @@ -43,8 +43,8 @@ pub struct Options { /// /// Default: true /// - /// [`null`]: trait.LuaSerdeExt.html#tymethod.null - /// [`Nil`]: ../enum.Value.html#variant.Nil + /// [`null`]: ../trait.LuaSerdeExt.html#tymethod.null + /// [`Nil`]: ../../enum.Value.html#variant.Nil pub serialize_unit_to_null: bool, } @@ -59,12 +59,12 @@ impl Default for Options { } impl<'lua> Serializer<'lua> { - /// Creates a new instance of Lua Serializer with default options + /// Creates a new Lua Serializer with default options. pub fn new(lua: &'lua Lua) -> Self { Self::new_with_options(lua, Options::default()) } - /// Creates a new instance of Lua Serializer with custom options + /// Creates a new Lua Serializer with custom options. pub fn new_with_options(lua: &'lua Lua, options: Options) -> Self { Serializer { lua, options } } @@ -267,6 +267,7 @@ impl<'lua> ser::Serializer for Serializer<'lua> { } } +#[doc(hidden)] pub struct SerializeVec<'lua> { table: Table<'lua>, options: Options, @@ -330,6 +331,7 @@ impl<'lua> ser::SerializeTupleStruct for SerializeVec<'lua> { } } +#[doc(hidden)] pub struct SerializeTupleVariant<'lua> { name: String<'lua>, table: Table<'lua>, @@ -358,6 +360,7 @@ impl<'lua> ser::SerializeTupleVariant for SerializeTupleVariant<'lua> { } } +#[doc(hidden)] pub struct SerializeMap<'lua> { table: Table<'lua>, key: Option<Value<'lua>>, @@ -412,6 +415,7 @@ impl<'lua> ser::SerializeStruct for SerializeMap<'lua> { } } +#[doc(hidden)] pub struct SerializeStructVariant<'lua> { name: String<'lua>, table: Table<'lua>, |