pub enum Value {
None,
Bool(bool),
Int(i64),
Float(f32),
Object(Arc<Object>),
Ref(Arc<RwLock<MutObject>>),
Weak(Weak<RwLock<MutObject>>),
}Expand description
A value enumeration.
The value enumeration represents a value of the Unlab scripting language.
Variants§
None
A none value.
Bool(bool)
A boolean value.
Int(i64)
An integer number.
Float(f32)
Floating-point number.
Object(Arc<Object>)
An immutablke object.
Ref(Arc<RwLock<MutObject>>)
A strong reference to a mutable object.
Weak(Weak<RwLock<MutObject>>)
A weak reference to a mutable object.
Implementations§
Source§impl Value
impl Value
Sourcepub fn to_opt_bool(&self) -> Option<bool>
pub fn to_opt_bool(&self) -> Option<bool>
Converts the value to a boolean value if the value is a boolean type, otherwise this
method returns None.
Sourcepub fn to_opt_i64(&self) -> Option<i64>
pub fn to_opt_i64(&self) -> Option<i64>
Converts the value to an integer number if the value is an integer type or floating-point
type, otherwise this method returns None.
Sourcepub fn to_opt_f32(&self) -> Option<f32>
pub fn to_opt_f32(&self) -> Option<f32>
Converts the value to a floating-point number if the value is an integer type or
floating-point type, otherwise this method returns None.
Sourcepub fn to_opt_string(&self) -> Option<String>
pub fn to_opt_string(&self) -> Option<String>
Converts the value to a string if the value is a string type, otherwise this method
returns None.
Sourcepub fn is_fun(&self) -> bool
pub fn is_fun(&self) -> bool
Returns true if the value is a function or a built-in function, otherwise false.
Sourcepub fn eq_with_types(&self, value: &Value) -> Result<bool>
pub fn eq_with_types(&self, value: &Value) -> Result<bool>
Returns true if two values are equal with types, otherwise false.
This method also compares types of two values for integer numbers and floating-point
numbers. If two values are weak references, this method compares their pointers instead
values. If two values are matrices, this method doesn’t compare two values and returns
false.
Sourcepub fn eq_without_types(&self, value: &Value) -> Result<bool>
pub fn eq_without_types(&self, value: &Value) -> Result<bool>
Returns true if two values are equal without types, otherwise false.
This method doesn’t compare types of two values for integer numbers and floating-point
numbers. If two values are weak references, this method compares their pointers instead
values. If two values are matrices, this method doesn’t compare two values and returns
false.
Sourcepub fn nearly_eq_with_types(&self, value: &Value, eps: f32) -> Result<bool>
pub fn nearly_eq_with_types(&self, value: &Value, eps: f32) -> Result<bool>
Returns true if two values are nearly equal with types, otherwise false.
If absolute difference between two numbers is less than or equal to the epsilon, two
numbers are nearly equal for floating-point numbers, matrix arrays, and matrix row slices.
Other values are compered as for eq_with_types.
Sourcepub fn nearly_eq_without_types(&self, value: &Value, eps: f32) -> Result<bool>
pub fn nearly_eq_without_types(&self, value: &Value, eps: f32) -> Result<bool>
Returns true if two values are nearly equal without types, otherwise false.
If absolute difference between two numbers is less than or equal to the epsilon, two
numbers are nearly equal for numbers, matrix arrays, and matrix row slices. Other values
are compered as for eq_without_types.
Sourcepub fn dot1<F>(&self, err_msg: &str, f: F) -> Result<Value>
pub fn dot1<F>(&self, err_msg: &str, f: F) -> Result<Value>
Applies the function with one argument for a dot operation.
If one element of one value or one field of one value is a floating-point number or a matrix, this method applies the function to one argument for this element or this field. If this element or this field is an array or a structure, this method recursively invokes itself for this element or this field. This method ignores this element or this field otherwise. This method returns an error with the error message if one value isn’t an array or an structure.
Sourcepub fn dot2<F>(&self, value: &Value, err_msg: &str, f: F) -> Result<Value>
pub fn dot2<F>(&self, value: &Value, err_msg: &str, f: F) -> Result<Value>
Applies the function with two arguments for a dot operation.
If two elements of two values or two fields of two values are floating-point numbers or matrices, this method applies the function to two arguments for these elements or these fields. If these elements or these fields are arrays or structures, this method recursively invokes itself for these elements or these fields. This method compares these elements or these fields otherwise. If these elements or these fields aren’t equal, this method returns an error. This method returns an error with the error message if two values aren’t arrays or structures.
Sourcepub fn apply(
&self,
interp: &mut Interp,
env: &mut Env,
arg_values: &[Value],
) -> Result<Value>
pub fn apply( &self, interp: &mut Interp, env: &mut Env, arg_values: &[Value], ) -> Result<Value>
Applies the function to the arguments.
See Interp::apply_fun.
Sourcepub fn elem(&self, idx_value: &Value) -> Result<Value>
pub fn elem(&self, idx_value: &Value) -> Result<Value>
Returns the element or the field if the value has the element or the field, otherwise
None or an error.
If the value isn’t a string, a matrix array, a matrix row slice, or a mutable object, this method returns an error.
Sourcepub fn set_elem(&self, idx_value: &Value, value: Value) -> Result<()>
pub fn set_elem(&self, idx_value: &Value, value: Value) -> Result<()>
Sets the element or the field for the value.
If the value isn’t a mutable object, this method returns an error.
Sourcepub fn field(&self, ident: &String) -> Result<Value>
pub fn field(&self, ident: &String) -> Result<Value>
Returns the field if the value has the field, otherwise None or an error.
If the value isn’t a structure, this method returns an error.
Sourcepub fn set_field(&self, ident: String, value: Value) -> Result<()>
pub fn set_field(&self, ident: String, value: Value) -> Result<()>
Sets the field for the value.
If the value isn’t a structure, this method returns an error.
Sourcepub fn unary_op(&self, op: UnaryOp) -> Result<Value>
pub fn unary_op(&self, op: UnaryOp) -> Result<Value>
Performs an operation on one value for the unary operator.
Sourcepub fn bin_op(&self, op: BinOp, value: &Value) -> Result<Value>
pub fn bin_op(&self, op: BinOp, value: &Value) -> Result<Value>
Performs an operation on two values for the binary operator.
Sourcepub fn iter(&self) -> Result<Option<Iter<'_>>>
pub fn iter(&self) -> Result<Option<Iter<'_>>>
Returns an interator if the value is iterable, otherwise None.
Sourcepub fn to_matrix_array(&self) -> Result<Value>
pub fn to_matrix_array(&self) -> Result<Value>
Converts the value to a matrix array.
If the value isn’t a matrix or a matrix array, this method returns an error.
Trait Implementations§
Source§impl AddAssign for Value
impl AddAssign for Value
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl AddAssign<&Value> for Value
impl AddAssign<&Value> for Value
Source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl DivAssign for Value
impl DivAssign for Value
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl DivAssign<&Value> for Value
impl DivAssign<&Value> for Value
Source§fn div_assign(&mut self, rhs: &Self)
fn div_assign(&mut self, rhs: &Self)
/= operation. Read moreSource§impl MulAssign for Value
impl MulAssign for Value
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl MulAssign<&Value> for Value
impl MulAssign<&Value> for Value
Source§fn mul_assign(&mut self, rhs: &Self)
fn mul_assign(&mut self, rhs: &Self)
*= operation. Read moreSource§impl PartialOrd for Value
impl PartialOrd for Value
Auto Trait Implementations§
impl Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnsafeUnpin for Value
impl UnwindSafe for Value
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.