summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/serde/mod.rs4
-rw-r--r--src/value.rs6
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",