mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
Allow exhaustive match on Value.
It was not possible because `ValueRef` variant in `Value::Other` was private. Closes #502 and #503
This commit is contained in:
@@ -4,7 +4,7 @@ use std::os::raw::{c_int, c_void};
|
||||
use crate::state::{RawLua, WeakLua};
|
||||
|
||||
/// A reference to a Lua (complex) value stored in the Lua auxiliary thread.
|
||||
pub(crate) struct ValueRef {
|
||||
pub struct ValueRef {
|
||||
pub(crate) lua: WeakLua,
|
||||
pub(crate) index: c_int,
|
||||
pub(crate) drop: bool,
|
||||
|
||||
+1
-2
@@ -67,8 +67,7 @@ pub enum Value {
|
||||
/// `Error` is a special builtin userdata type. When received from Lua it is implicitly cloned.
|
||||
Error(Box<Error>),
|
||||
/// Any other value not known to mlua (eg. LuaJIT CData).
|
||||
#[allow(private_interfaces)]
|
||||
Other(ValueRef),
|
||||
Other(#[doc(hidden)] ValueRef),
|
||||
}
|
||||
|
||||
pub use self::Value::Nil;
|
||||
|
||||
@@ -296,3 +296,25 @@ fn test_value_conversions() -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_value_exhaustive_match() {
|
||||
match Value::Nil {
|
||||
Value::Nil => {}
|
||||
Value::Boolean(_) => {}
|
||||
Value::LightUserData(_) => {}
|
||||
Value::Integer(_) => {}
|
||||
Value::Number(_) => {}
|
||||
#[cfg(feature = "luau")]
|
||||
Value::Vector(_) => {}
|
||||
Value::String(_) => {}
|
||||
Value::Table(_) => {}
|
||||
Value::Function(_) => {}
|
||||
Value::Thread(_) => {}
|
||||
Value::UserData(_) => {}
|
||||
#[cfg(feature = "luau")]
|
||||
Value::Buffer(_) => {}
|
||||
Value::Error(_) => {}
|
||||
Value::Other(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user