Skip to content

Commit

Permalink
Allow exhaustive match on Value.
Browse files Browse the repository at this point in the history
It was not possible because `ValueRef` variant in `Value::Other` was private.
Closes #502 and #503
  • Loading branch information
khvzak committed Dec 10, 2024
1 parent 91e069a commit cd4091f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/types/value_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions tests/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {}
}
}

0 comments on commit cd4091f

Please sign in to comment.