[][src]Trait ketos::structs::StructValue

pub trait StructValue: Sized + Clone + ForeignValue {
    fn struct_name() -> &'static str;
fn from_fields(
        scope: &Scope,
        def: &Rc<StructDef>,
        fields: &mut [(Name, Value)]
    ) -> Result<Self, Error>;
fn field_names() -> &'static [&'static str];
fn get_field(
        &self,
        scope: &Scope,
        def: &Rc<StructDef>,
        name: Name
    ) -> Result<Value, Error>;
fn replace_fields(
        &mut self,
        scope: &Scope,
        def: &Rc<StructDef>,
        fields: &mut [(Name, Value)]
    ) -> Result<(), Error>; }

Implements functionality for Ketos struct values on a Rust type.

A type implementing StructValue may be constructed with new, will provide field access with . and can create modified values with .=.

An implementation of this trait can be generated using derive(StructValue) with the ketos_derive crate.

Required methods

fn struct_name() -> &'static str

Returns the struct name.

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

Creates a value from a list of fields.

An error should be returned if any fields are missing, superfluous, or the wrong type of value.

fn field_names() -> &'static [&'static str]

Returns a list of field names.

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

Returns a copy of a field as a Ketos Value.

If the named field does not exist, an error should be returned.

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

Modifies the value to replace named fields with provided values.

If any names are invalid or any values are of incorrect type, an error should be returned.

Loading content...

Implementors

Loading content...