Skip to main content

Value

Enum Value 

Source
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

Source

pub fn to_bool(&self) -> bool

Converts any value to a boolean value.

Source

pub fn to_i64(&self) -> i64

Converts any value to an integer number.

Source

pub fn to_f32(&self) -> f32

Converts any value to a floating-point number.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_fun(&self) -> bool

Returns true if the value is a function or a built-in function, otherwise false.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn dot1<F>(&self, err_msg: &str, f: F) -> Result<Value>
where F: FnMut(&Value) -> 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.

Source

pub fn dot2<F>(&self, value: &Value, err_msg: &str, f: F) -> Result<Value>
where F: FnMut(&Value, &Value) -> 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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn unary_op(&self, op: UnaryOp) -> Result<Value>

Performs an operation on one value for the unary operator.

Source

pub fn bin_op(&self, op: BinOp, value: &Value) -> Result<Value>

Performs an operation on two values for the binary operator.

Source

pub fn iter(&self) -> Result<Option<Iter<'_>>>

Returns an interator if the value is iterable, otherwise None.

Source

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 Add for Value

Source§

type Output = Value

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<&Value> for Value

Source§

type Output = Value

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Value) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<&Value> for &Value

Source§

type Output = Value

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Value) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Value> for &Value

Source§

type Output = Value

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Value) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign for Value

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl AddAssign<&Value> for Value

Source§

fn add_assign(&mut self, rhs: &Self)

Performs the += operation. Read more
Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Value

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div for Value

Source§

type Output = Value

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<&Value> for Value

Source§

type Output = Value

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Value) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<&Value> for &Value

Source§

type Output = Value

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Value) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Value> for &Value

Source§

type Output = Value

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Value) -> Self::Output

Performs the / operation. Read more
Source§

impl DivAssign for Value

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl DivAssign<&Value> for Value

Source§

fn div_assign(&mut self, rhs: &Self)

Performs the /= operation. Read more
Source§

impl Mul for Value

Source§

type Output = Value

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&Value> for Value

Source§

type Output = Value

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Value) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&Value> for &Value

Source§

type Output = Value

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Value) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Value> for &Value

Source§

type Output = Value

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Value) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign for Value

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl MulAssign<&Value> for Value

Source§

fn mul_assign(&mut self, rhs: &Self)

Performs the *= operation. Read more
Source§

impl Neg for Value

Source§

type Output = Value

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Neg for &Value

Source§

type Output = Value

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Not for Value

Source§

type Output = Value

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl Not for &Value

Source§

type Output = Value

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Value

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Value

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub for Value

Source§

type Output = Value

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<&Value> for Value

Source§

type Output = Value

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Value) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<&Value> for &Value

Source§

type Output = Value

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Value) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Value> for &Value

Source§

type Output = Value

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Value) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign for Value

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl SubAssign<&Value> for Value

Source§

fn sub_assign(&mut self, rhs: &Self)

Performs the -= operation. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more