pub enum Value<'host> {
Unit,
Tuple(Tuple<Value<'host>>),
Borrow(&'host dyn Extern, Option<Rc<Value<'host>>>),
Owned(Rc<dyn ExternOwned>, Option<Rc<Value<'host>>>),
I64(i64),
Bool(bool),
String(Rc<str>),
Function(Rc<Function<'host>>),
EnumVariant(Rc<EnumVariant<'host>>),
Option {
contents: Option<Rc<Value<'host>>>,
ty: ComplexType,
},
Mut(Mut<'host>),
Type(Type),
}Expand description
Variants§
Unit
Unit is the absense of a value. It can be thought of as both an empty tuple and an empty named tuple.
Tuple(Tuple<Value<'host>>)
Borrow(&'host dyn Extern, Option<Rc<Value<'host>>>)
Owned(Rc<dyn ExternOwned>, Option<Rc<Value<'host>>>)
I64(i64)
Bool(bool)
String(Rc<str>)
Function(Rc<Function<'host>>)
EnumVariant(Rc<EnumVariant<'host>>)
Option
Mut(Mut<'host>)
Type(Type)
Implementations§
Source§impl<'host> Value<'host>
impl<'host> Value<'host>
Sourcepub fn to_static(&self) -> Option<StaticValue>
pub fn to_static(&self) -> Option<StaticValue>
Returns None if self contains any Value::Borrow or Value::Mut.
Value::Borrow is not static for obvious reasons,
and Value::Mut cannot be made static because of refcell subtyping.
Instead, hosts using to_static should provide mutable state outside of
the espy runtime.
Sourcepub fn get(&self, index: i64) -> Result<Value<'host>, Error>
pub fn get(&self, index: i64) -> Result<Value<'host>, Error>
Convenience method for indexing values of various types by an integer.
Usually this is most useful for reading function arguments by index, which are passed as a tuple by convention.
§Errors
Returns ErrorKind::IndexNotFound if self cannot be indexed or the index is out of range for the container.
Extern and ExternOwned implementations may return arbitary errors.
Sourcepub fn find(&self, index: Rc<str>) -> Result<Value<'host>, Error>
pub fn find(&self, index: Rc<str>) -> Result<Value<'host>, Error>
Convenience methods for indexing values of various types by a string.
§Errors
Returns Error::index_not_found if self cannot be indexed or the index is not found in the container.
Value::Borrow and Value::Owned implementations may return arbitary errors.
Sourcepub fn index(
&self,
index: impl Into<Value<'host>>,
) -> Result<Value<'host>, Error>
pub fn index( &self, index: impl Into<Value<'host>>, ) -> Result<Value<'host>, Error>
Convenience methods for indexing values of various types.
§Errors
Returns Error::index_not_found if self cannot be indexed or the index is not found in the container.
Value::Borrow and Value::Owned implementations may return arbitary errors.
Sourcepub fn downcast_extern<T: Any>(&self) -> Option<&T>
pub fn downcast_extern<T: Any>(&self) -> Option<&T>
Attempts to downcast instances of Value::Borrow and Value::Owned into &T.
Note that Extern and ExternOwned implementations have to opt into this behavior
by implementing their any functions.
The default any implementation will result in this function returning None.
Sourcepub fn eq(self, other: Self) -> Result<bool, Error>
pub fn eq(self, other: Self) -> Result<bool, Error>
§Errors
Returns an error if self and other are incomparable.
Sourcepub fn type_of(&self) -> Result<ComplexType, Error>
pub fn type_of(&self) -> Result<ComplexType, Error>
§Errors
Returns an error if a mutable reference is being mutably borrowed.
This can be safely ignored by the host if it has not deliberately borrowed an espy value.
pub fn concat(self, r: Self) -> Self
pub fn borrow(external: &'host dyn Extern) -> Self
pub fn owned(external: Rc<dyn ExternOwned>) -> Self
Source§impl<'host> Value<'host>
TryInto shortcuts
impl<'host> Value<'host>
TryInto shortcuts
Sourcepub fn into_unit(self) -> Result<(), Error>
pub fn into_unit(self) -> Result<(), Error>
§Errors
Returns an error if self is not a Value::Unit
Sourcepub fn into_tuple(self) -> Result<Tuple<Value<'host>>, Error>
pub fn into_tuple(self) -> Result<Tuple<Value<'host>>, Error>
§Errors
Returns an error if self is not a Value::Tuple
Sourcepub fn into_vec(self) -> Vec<Value<'host>>
pub fn into_vec(self) -> Vec<Value<'host>>
Turns this value into a vector of values.
Value::Tuple’s members will be collected into the vector.
Value::Unit will produce an empty vector.
All other variants will produce a vector with just one member.
Sourcepub fn into_bool(self) -> Result<bool, Error>
pub fn into_bool(self) -> Result<bool, Error>
§Errors
Returns an error if self is not a Value::Bool
Sourcepub fn into_i64(self) -> Result<i64, Error>
pub fn into_i64(self) -> Result<i64, Error>
§Errors
Returns an error if self is not a Value::I64
Sourcepub fn into_str(self) -> Result<Rc<str>, Error>
pub fn into_str(self) -> Result<Rc<str>, Error>
§Errors
Returns an error if self is not a Value::String
pub fn as_str(&self) -> Option<&str>
Sourcepub fn into_function(self) -> Result<Function<'host>, Error>
pub fn into_function(self) -> Result<Function<'host>, Error>
§Errors
Returns an error if self is not a Value::Function
Sourcepub fn into_enum_variant(self) -> Result<Rc<EnumVariant<'host>>, Error>
pub fn into_enum_variant(self) -> Result<Rc<EnumVariant<'host>>, Error>
§Errors
Returns an error if self is not a Value::EnumVariant
Sourcepub fn into_option(self) -> Result<Option<Value<'host>>, Error>
pub fn into_option(self) -> Result<Option<Value<'host>>, Error>
§Errors
Returns an error if self is not a Value::Option
Sourcepub fn into_refcell(self) -> Result<Rc<RefCell<Value<'host>>>, Error>
pub fn into_refcell(self) -> Result<Rc<RefCell<Value<'host>>>, Error>
§Errors
Returns an error if self is not a Value::Mut
Sourcepub fn into_complex_type(self) -> Result<ComplexType, Error>
pub fn into_complex_type(self) -> Result<ComplexType, Error>
§Errors
Returns an error if self is not a Value::Type or Value::Tuple or types.
Sourcepub fn into_enum_type(self) -> Result<Rc<EnumType>, Error>
pub fn into_enum_type(self) -> Result<Rc<EnumType>, Error>
§Errors
Returns an error if self is not a Value::Type containing a Type::Enum