Skip to content

Commit cd4091f

Browse files
committed
Allow exhaustive match on Value.
It was not possible because `ValueRef` variant in `Value::Other` was private. Closes #502 and #503
1 parent 91e069a commit cd4091f

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/types/value_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::os::raw::{c_int, c_void};
44
use crate::state::{RawLua, WeakLua};
55

66
/// A reference to a Lua (complex) value stored in the Lua auxiliary thread.
7-
pub(crate) struct ValueRef {
7+
pub struct ValueRef {
88
pub(crate) lua: WeakLua,
99
pub(crate) index: c_int,
1010
pub(crate) drop: bool,

src/value.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ pub enum Value {
6767
/// `Error` is a special builtin userdata type. When received from Lua it is implicitly cloned.
6868
Error(Box<Error>),
6969
/// Any other value not known to mlua (eg. LuaJIT CData).
70-
#[allow(private_interfaces)]
71-
Other(ValueRef),
70+
Other(#[doc(hidden)] ValueRef),
7271
}
7372

7473
pub use self::Value::Nil;

tests/value.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,25 @@ fn test_value_conversions() -> Result<()> {
296296

297297
Ok(())
298298
}
299+
300+
#[test]
301+
fn test_value_exhaustive_match() {
302+
match Value::Nil {
303+
Value::Nil => {}
304+
Value::Boolean(_) => {}
305+
Value::LightUserData(_) => {}
306+
Value::Integer(_) => {}
307+
Value::Number(_) => {}
308+
#[cfg(feature = "luau")]
309+
Value::Vector(_) => {}
310+
Value::String(_) => {}
311+
Value::Table(_) => {}
312+
Value::Function(_) => {}
313+
Value::Thread(_) => {}
314+
Value::UserData(_) => {}
315+
#[cfg(feature = "luau")]
316+
Value::Buffer(_) => {}
317+
Value::Error(_) => {}
318+
Value::Other(_) => {}
319+
}
320+
}

0 commit comments

Comments
 (0)