Skip to main content

Factory

Trait Factory 

Source
pub trait Factory: Send + Sync {
    // Required methods
    fn opaque(&self, value: Arc<dyn RuntimeObject>) -> Result<Value>;
    fn class_stub(&self, id: ClassId, symbol: Symbol) -> Result<Value>;
    fn nil(&self) -> Result<Value>;
    fn bool(&self, value: bool) -> Result<Value>;
    fn symbol(&self, value: Symbol) -> Result<Value>;
    fn string(&self, value: String) -> Result<Value>;
    fn bytes(&self, value: Vec<u8>) -> Result<Value>;
    fn list(&self, items: Vec<Value>) -> Result<Value>;
    fn table(&self, entries: Vec<(Symbol, Value)>) -> Result<Value>;
    fn expr(&self, expr: Expr) -> Result<Value>;
    fn number_literal(&self, domain: Symbol, canonical: String) -> Result<Value>;

    // Provided method
    fn table_one(&self, key: Symbol, value: Value) -> Result<Value> { ... }
}
Expand description

Constructs runtime Values from kernel data.

The kernel defines this contract and threads a &dyn Factory through every Cx; libraries supply the concrete object representations the factory hands back. DefaultFactory provides a minimal built-in implementation for scalars and core collections.

Required Methods§

Source

fn opaque(&self, value: Arc<dyn RuntimeObject>) -> Result<Value>

Wraps an arbitrary runtime object as an opaque value.

Source

fn class_stub(&self, id: ClassId, symbol: Symbol) -> Result<Value>

Builds a class value from a class id and symbol.

Source

fn nil(&self) -> Result<Value>

Builds the nil value.

Source

fn bool(&self, value: bool) -> Result<Value>

Builds a boolean value.

Source

fn symbol(&self, value: Symbol) -> Result<Value>

Builds a symbol value.

Source

fn string(&self, value: String) -> Result<Value>

Builds a string value.

Source

fn bytes(&self, value: Vec<u8>) -> Result<Value>

Builds a byte-string value.

Source

fn list(&self, items: Vec<Value>) -> Result<Value>

Builds a list value from its items.

Source

fn table(&self, entries: Vec<(Symbol, Value)>) -> Result<Value>

Builds a table value from its entries.

Source

fn expr(&self, expr: Expr) -> Result<Value>

Builds a value carrying an Expr.

Source

fn number_literal(&self, domain: Symbol, canonical: String) -> Result<Value>

Builds a number value from a domain symbol and canonical text.

Provided Methods§

Source

fn table_one(&self, key: Symbol, value: Value) -> Result<Value>

Builds a single-entry table; convenience over table.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§