Trait ketos::value::ForeignValue
[−]
[src]
pub trait ForeignValue: AnyValue + Debug { fn is_equal_to(&self, rhs: &ForeignValue) -> Result<bool, ExecError>; fn type_name(&self) -> &'static str; fn compare_to(&self, _rhs: &ForeignValue) -> Result<Ordering, ExecError> { ... } fn compare_to_value(&self, rhs: &Value) -> Result<Ordering, ExecError> { ... } fn is_identical_to(&self, rhs: &ForeignValue) -> bool { ... } fn is_equal_to_value(&self, rhs: &Value) -> Result<bool, ExecError> { ... } fn fmt_debug(&self, _names: &NameStore, f: &mut Formatter) -> Result { ... } fn fmt_display(&self, names: &NameStore, f: &mut Formatter) -> Result { ... } fn is_type(&self, name: &str) -> bool { ... } fn call_value(&self, _scope: &Scope, _args: &mut [Value]) -> Result<Value, Error> { ... } }
Represents a type of value defined outside the core interpreter.
Required Methods
fn is_equal_to(&self, rhs: &ForeignValue) -> Result<bool, ExecError>
Tests for equality between two values of a foreign type.
fn type_name(&self) -> &'static str
Return the value's type name.
Provided Methods
fn compare_to(&self, _rhs: &ForeignValue) -> Result<Ordering, ExecError>
Performs ordered comparison between two values of a foreign type.
If a true, Ord
-like comparison cannot be made,
ExecError::CannotCompare(..)
should be returned.
The default implementation unconditionally returns an error.
fn compare_to_value(&self, rhs: &Value) -> Result<Ordering, ExecError>
Performs ordered comparison between two values.
This method need only be implemented if a value of the foreign type may be compared with core value types.
fn is_identical_to(&self, rhs: &ForeignValue) -> bool
Returns whether the two values are identical.
This concept is the same as equality, except in the case of floating
point values, where two NaN
values are considered identical.
A type implementing ForeignValue
need only implement is_identical
if it contains a float-type value or emulates some equality relationship
similar to NaN
.
fn is_equal_to_value(&self, rhs: &Value) -> Result<bool, ExecError>
Tests for equality between two values.
This method need only be implemented if a value of the foreign type may be compared with core value types.
fn fmt_debug(&self, _names: &NameStore, f: &mut Formatter) -> Result
Format the value in debugging mode.
The default implementation uses the type's fmt::Debug
representation.
fn fmt_display(&self, names: &NameStore, f: &mut Formatter) -> Result
Format the value in display mode.
The default implementation formats the value in debugging mode.
fn is_type(&self, name: &str) -> bool
Returns whether this value is of the named type.
The default implementation checks against the value of self.type_name()
.
fn call_value(&self, _scope: &Scope, _args: &mut [Value]) -> Result<Value, Error>
Calls the value as a function.
The default implementation unconditionally returns an error.
Methods
impl ForeignValue
[src]
fn is<T: Any>(&self) -> bool
Returns whether the contained value is of the given type.
fn downcast_ref<T: Any>(&self) -> Option<&T>
Returns a reference to the contained value, if it is of the given type.
fn downcast_mut<T: Any>(&mut self) -> Option<&mut T>
Returns a mutable reference to the contained value, if it is of the given type.