pub enum LuaValue {
False,
Function,
Nil,
Number(f64),
String(String),
Table,
True,
Unknown,
}
Expand description
Represents an evaluated Expression result.
Variants§
Implementations§
Source§impl LuaValue
impl LuaValue
Sourcepub fn is_truthy(&self) -> Option<bool>
pub fn is_truthy(&self) -> Option<bool>
As defined in Lua, all values are considered true, except for false and nil. An option is returned as the LuaValue may be unknown, so it would return none.
// the values considered false
assert!(!LuaValue::False.is_truthy().unwrap());
assert!(!LuaValue::Nil.is_truthy().unwrap());
// all the others are true
assert!(LuaValue::True.is_truthy().unwrap());
assert!(LuaValue::Table.is_truthy().unwrap());
assert!(LuaValue::Number(0.0).is_truthy().unwrap());
assert!(LuaValue::String("hello".to_owned()).is_truthy().unwrap());
// unknown case
assert!(LuaValue::Unknown.is_truthy().is_none());
Sourcepub fn map_if_truthy<F>(self, map: F) -> Selfwhere
F: Fn(Self) -> Self,
pub fn map_if_truthy<F>(self, map: F) -> Selfwhere
F: Fn(Self) -> Self,
If the value is unknown, this will also return unknown value. In the other case, if the
value is considered truthy (see is_truthy
function), it will call the given function to
get the mapped value.
Sourcepub fn map_if_truthy_else<F, G>(self, map: F, default: G) -> Self
pub fn map_if_truthy_else<F, G>(self, map: F, default: G) -> Self
Like the map_if_truthy
method, except that instead of returning the same value when the
it is falsy, it calls the default callback to obtain another value.
Sourcepub fn to_expression(self) -> Option<Expression>
pub fn to_expression(self) -> Option<Expression>
Attempt to convert the Lua value into an expression node.
Sourcepub fn number_coercion(self) -> Self
pub fn number_coercion(self) -> Self
Attempt to convert the Lua value into a number value. This will convert strings when possible and return the same value otherwise.
Sourcepub fn string_coercion(self) -> Self
pub fn string_coercion(self) -> Self
Attempt to convert the Lua value into a string value. This will convert numbers when possible and return the same value otherwise.
Trait Implementations§
impl StructuralPartialEq for LuaValue
Auto Trait Implementations§
impl Freeze for LuaValue
impl RefUnwindSafe for LuaValue
impl Send for LuaValue
impl Sync for LuaValue
impl Unpin for LuaValue
impl UnwindSafe for LuaValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<I, T> ExtractContext<I, ()> for T
impl<I, T> ExtractContext<I, ()> for T
Source§fn extract_context(self, _original_input: I)
fn extract_context(self, _original_input: I)
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more