[][src]Trait ketos::structs::StructDefinition

pub trait StructDefinition: Any {
    fn is_instance(&self, value: &Value, def: &Rc<StructDef>) -> bool;
fn from_fields(
        &self,
        scope: &Scope,
        def: &Rc<StructDef>,
        fields: &mut [(Name, Value)]
    ) -> Result<Value, Error>;
fn get_field(
        &self,
        scope: &Scope,
        def: &Rc<StructDef>,
        value: &Value,
        field: Name
    ) -> Result<Value, Error>;
fn field_names(&self) -> Vec<Name>;
fn replace_fields(
        &self,
        scope: &Scope,
        def: &Rc<StructDef>,
        value: Value,
        fields: &mut [(Name, Value)]
    ) -> Result<Value, Error>; fn size(&self) -> usize { ... } }

Implements construction and field access for Struct and struct-like values.

Required methods

fn is_instance(&self, value: &Value, def: &Rc<StructDef>) -> bool

Returns whether the given value is an instance of the given StructDef.

def is the StructDef instance for this definition.

fn from_fields(
    &self,
    scope: &Scope,
    def: &Rc<StructDef>,
    fields: &mut [(Name, Value)]
) -> Result<Value, Error>

Creates a value of this struct type from the given list of fields.

def is the StructDef instance for this definition.

fn get_field(
    &self,
    scope: &Scope,
    def: &Rc<StructDef>,
    value: &Value,
    field: Name
) -> Result<Value, Error>

Returns a field from a struct value.

def is the StructDef instance for this definition.

fn field_names(&self) -> Vec<Name>

Returns a list of field names.

fn replace_fields(
    &self,
    scope: &Scope,
    def: &Rc<StructDef>,
    value: Value,
    fields: &mut [(Name, Value)]
) -> Result<Value, Error>

Returns a new struct value with a set of fields replaced with given values.

def is the StructDef instance for this definition.

Loading content...

Provided methods

fn size(&self) -> usize

Returns an estimate of the memory held by this definition.

The result will be used in applying memory restrictions to executing code. The result MUST NOT change for the lifetime of the value.

Loading content...

Methods

impl dyn StructDefinition[src]

pub fn is<T: StructDefinition>(&self) -> bool[src]

Returns whether the contained value is of the given type.

pub fn downcast<T: StructDefinition>(bx: Box<Self>) -> Result<Box<T>, Box<Self>>[src]

Attempts to downcast a Box<Trait> to a concrete type.

pub fn downcast_rc<T: StructDefinition>(rc: Rc<Self>) -> Result<Rc<T>, Rc<Self>>[src]

Returns an owned Rc reference to the contained value, if it is of the given type.

pub fn downcast_ref<T: StructDefinition>(&self) -> Option<&T>[src]

Returns a reference to the contained value, if it is of the given type.

pub fn downcast_mut<T: StructDefinition>(&mut self) -> Option<&mut T>[src]

Returns a mutable reference to the contained value, if it is of the given type.

Implementors

impl StructDefinition for StructValueDef[src]

impl<T: StructValue> StructDefinition for ForeignStructDef<T>[src]

Loading content...