Value

Enum Value 

Source
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

The root type of every espy value. All interoperation starts here.

Don’t be afraid to Clone this type; it contains only Copy types and Rcs.

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

Fields

§contents: Option<Rc<Value<'host>>>
§

Mut(Mut<'host>)

§

Type(Type)

Implementations§

Source§

impl<'host> Value<'host>

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn downcast_extern<T>(&self) -> Option<&T>
where T: Any,

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.

Source

pub fn eq(self, other: Value<'host>) -> Result<bool, Error>

§Errors

Returns an error if self and other are incomparable.

Source

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.

Source

pub fn concat(self, r: Value<'host>) -> Value<'host>

Source

pub fn borrow(external: &'host dyn Extern) -> Value<'host>

Source

pub fn owned(external: Rc<dyn ExternOwned>) -> Value<'host>

Source§

impl<'host> Value<'host>

TryInto shortcuts

Source

pub fn into_unit(self) -> Result<(), Error>

§Errors

Returns an error if self is not a Value::Unit

Source

pub fn into_tuple(self) -> Result<Tuple<Value<'host>>, Error>

§Errors

Returns an error if self is not a Value::Tuple

Source

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.

Source

pub fn into_bool(self) -> Result<bool, Error>

§Errors

Returns an error if self is not a Value::Bool

Source

pub fn into_i64(self) -> Result<i64, Error>

§Errors

Returns an error if self is not a Value::I64

Source

pub fn into_str(self) -> Result<Rc<str>, Error>

§Errors

Returns an error if self is not a Value::String

Source

pub fn as_str(&self) -> Option<&str>

Source

pub fn into_function(self) -> Result<Function<'host>, Error>

§Errors

Returns an error if self is not a Value::Function

Source

pub fn into_enum_variant(self) -> Result<Rc<EnumVariant<'host>>, Error>

§Errors

Returns an error if self is not a Value::EnumVariant

Source

pub fn into_option(self) -> Result<Option<Value<'host>>, Error>

§Errors

Returns an error if self is not a Value::Option

Source

pub fn into_refcell(self) -> Result<Rc<RefCell<Value<'host>>>, Error>

§Errors

Returns an error if self is not a Value::Mut

Source

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.

Source

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

Trait Implementations§

Source§

impl<'host> Clone for Value<'host>

Source§

fn clone(&self) -> Value<'host>

Returns a duplicate of the value. Read more
1.0.0§

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<(), Error>

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

impl From<&str> for Value<'_>

Source§

fn from(s: &str) -> Value<'_>

Converts to this type from the input type.
Source§

impl<'host, K, const N: usize> From<[(K, Value<'host>); N]> for Value<'host>
where K: Into<Rc<str>>,

Source§

fn from(value: [(K, Value<'host>); N]) -> Value<'host>

Converts to this type from the input type.
Source§

impl<'host, T, const N: usize> From<[T; N]> for Value<'host>
where T: Into<Value<'host>>,

Source§

fn from(value: [T; N]) -> Value<'host>

Converts to this type from the input type.
Source§

impl From<()> for Value<'_>

Source§

fn from(_: ()) -> Value<'_>

Converts to this type from the input type.
Source§

impl From<ComplexType> for Value<'_>

Source§

fn from(value: ComplexType) -> Value<'_>

Converts to this type from the input type.
Source§

impl<'host> From<Function<'host>> for Value<'host>

Source§

fn from(f: Function<'host>) -> Value<'host>

Converts to this type from the input type.
Source§

impl From<Option<&str>> for Value<'_>

Source§

fn from(value: Option<&str>) -> Value<'_>

Converts to this type from the input type.
Source§

impl From<Option<()>> for Value<'_>

Source§

fn from(value: Option<()>) -> Value<'_>

Converts to this type from the input type.
Source§

impl<'host> From<Option<Rc<Value<'host>>>> for Value<'host>

Source§

fn from(value: Option<Rc<Value<'host>>>) -> Value<'host>

Converts to this type from the input type.
Source§

impl From<Option<Rc<str>>> for Value<'_>

Source§

fn from(value: Option<Rc<str>>) -> Value<'_>

Converts to this type from the input type.
Source§

impl<'host> From<Option<Value<'host>>> for Value<'host>

Source§

fn from(value: Option<Value<'host>>) -> Value<'host>

Converts to this type from the input type.
Source§

impl From<Option<bool>> for Value<'_>

Source§

fn from(value: Option<bool>) -> Value<'_>

Converts to this type from the input type.
Source§

impl From<Option<i64>> for Value<'_>

Source§

fn from(value: Option<i64>) -> Value<'_>

Converts to this type from the input type.
Source§

impl<'host> From<Rc<[(Rc<str>, Value<'host>)]>> for Value<'host>

Source§

fn from(value: Rc<[(Rc<str>, Value<'host>)]>) -> Value<'host>

Converts to this type from the input type.
Source§

impl<'host> From<Rc<[Value<'host>]>> for Value<'host>

Source§

fn from(value: Rc<[Value<'host>]>) -> Value<'host>

Converts to this type from the input type.
Source§

impl<'host> From<Rc<Function<'host>>> for Value<'host>

Source§

fn from(f: Rc<Function<'host>>) -> Value<'host>

Converts to this type from the input type.
Source§

impl From<Rc<str>> for Value<'_>

Source§

fn from(s: Rc<str>) -> Value<'_>

Converts to this type from the input type.
Source§

impl<'host, T> From<T> for Value<'host>
where T: Borrow<StaticValue>,

Source§

fn from(value: T) -> Value<'host>

Converts to this type from the input type.
Source§

impl From<Type> for Value<'_>

Source§

fn from(t: Type) -> Value<'_>

Converts to this type from the input type.
Source§

impl From<bool> for Value<'_>

Source§

fn from(value: bool) -> Value<'_>

Converts to this type from the input type.
Source§

impl From<i64> for Value<'_>

Source§

fn from(i: i64) -> Value<'_>

Converts to this type from the input type.
Source§

impl<'host> TryFrom<Value<'host>> for ComplexType

Source§

type Error = Error

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

fn try_from( value: Value<'host>, ) -> Result<ComplexType, <ComplexType as TryFrom<Value<'host>>>::Error>

Performs the conversion.
Source§

impl<'host> TryFrom<Value<'host>> for EnumType

Source§

type Error = Error

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

fn try_from( value: Value<'host>, ) -> Result<EnumType, <EnumType as TryFrom<Value<'host>>>::Error>

Performs the conversion.
Source§

impl<'host> TryFrom<Value<'host>> for EnumVariant<'host>

Source§

type Error = Error

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

fn try_from( value: Value<'host>, ) -> Result<EnumVariant<'host>, <EnumVariant<'host> as TryFrom<Value<'host>>>::Error>

Performs the conversion.
Source§

impl<'host> TryFrom<Value<'host>> for Function<'host>

Source§

type Error = Error

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

fn try_from( value: Value<'host>, ) -> Result<Function<'host>, <Function<'host> as TryFrom<Value<'host>>>::Error>

Performs the conversion.
Source§

impl<'host> TryFrom<Value<'host>> for Tuple<Value<'host>>

Source§

type Error = Error

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

fn try_from( value: Value<'host>, ) -> Result<Tuple<Value<'host>>, <Tuple<Value<'host>> as TryFrom<Value<'host>>>::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'host> Freeze for Value<'host>

§

impl<'host> !RefUnwindSafe for Value<'host>

§

impl<'host> !Send for Value<'host>

§

impl<'host> !Sync for Value<'host>

§

impl<'host> Unpin for Value<'host>

§

impl<'host> !UnwindSafe for Value<'host>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.