diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2023-05-06 22:53:40 +0100 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2023-05-06 22:53:40 +0100 |
commit | d951cb503f7d1c8e006f90c0954eb8e6bdbc3c92 (patch) | |
tree | f10e14f064ac3884fcd43656d0bcfcdad0e0c0b1 /src | |
parent | bbd2488f798e79dd8997a199fd3ada7945b295d1 (diff) | |
download | mlua-d951cb503f7d1c8e006f90c0954eb8e6bdbc3c92.zip |
Add `Value::NULL` constant
Diffstat (limited to 'src')
-rw-r--r-- | src/serde/mod.rs | 4 | ||||
-rw-r--r-- | src/value.rs | 6 |
2 files changed, 7 insertions, 3 deletions
diff --git a/src/serde/mod.rs b/src/serde/mod.rs index a4328df..8b83c21 100644 --- a/src/serde/mod.rs +++ b/src/serde/mod.rs @@ -1,7 +1,6 @@ //! (De)Serialization support using serde. use std::os::raw::c_void; -use std::ptr; use serde::{Deserialize, Serialize}; @@ -9,7 +8,6 @@ use crate::error::Result; use crate::lua::Lua; use crate::private::Sealed; use crate::table::Table; -use crate::types::LightUserData; use crate::util::check_stack; use crate::value::Value; @@ -200,7 +198,7 @@ pub trait LuaSerdeExt<'lua>: Sealed { impl<'lua> LuaSerdeExt<'lua> for Lua { fn null(&'lua self) -> Value<'lua> { - Value::LightUserData(LightUserData(ptr::null_mut())) + Value::NULL } fn array_metatable(&'lua self) -> Table<'lua> { diff --git a/src/value.rs b/src/value.rs index 74834a9..2678e4b 100644 --- a/src/value.rs +++ b/src/value.rs @@ -63,6 +63,12 @@ pub enum Value<'lua> { pub use self::Value::Nil; impl<'lua> Value<'lua> { + /// A special value (lightuserdata) to represent null value. + /// + /// It can be used in Lua tables without downsides of `nil`. + pub const NULL: Value<'static> = Value::LightUserData(LightUserData(ptr::null_mut())); + + /// Returns type name of this value. pub const fn type_name(&self) -> &'static str { match *self { Value::Nil => "nil", |