Skip to main content

Table

Trait Table 

Source
pub trait Table: RuntimeObject {
    // Required methods
    fn backend_symbol(&self) -> Symbol;
    fn get(&self, cx: &mut Cx, key: Symbol) -> Result<Value>;
    fn set(&self, cx: &mut Cx, key: Symbol, value: Value) -> Result<()>;
    fn has(&self, cx: &mut Cx, key: Symbol) -> Result<bool>;
    fn del(&self, cx: &mut Cx, key: Symbol) -> Result<Value>;
    fn keys(&self, cx: &mut Cx) -> Result<Vec<Symbol>>;
    fn entries(&self, cx: &mut Cx) -> Result<Vec<(Symbol, Value)>>;
    fn len(&self, cx: &mut Cx) -> Result<usize>;
    fn clear(&self, cx: &mut Cx) -> Result<()>;

    // Provided methods
    fn is_empty(&self, cx: &mut Cx) -> Result<bool> { ... }
    fn as_table_expr(&self, cx: &mut Cx) -> Result<Expr> { ... }
    fn table_eq(&self, cx: &mut Cx, other: &dyn Table) -> Result<bool> { ... }
}
Expand description

Universal map surface. Keys are symbols; values are runtime values.

Required Methods§

Source

fn backend_symbol(&self) -> Symbol

Symbol identifying the backend representation.

Source

fn get(&self, cx: &mut Cx, key: Symbol) -> Result<Value>

Looks up key, returning nil when absent.

Source

fn set(&self, cx: &mut Cx, key: Symbol, value: Value) -> Result<()>

Inserts or replaces the value for key.

Source

fn has(&self, cx: &mut Cx, key: Symbol) -> Result<bool>

Whether key is present.

Source

fn del(&self, cx: &mut Cx, key: Symbol) -> Result<Value>

Removes key, returning its prior value or nil.

Source

fn keys(&self, cx: &mut Cx) -> Result<Vec<Symbol>>

All keys, in backend order.

Source

fn entries(&self, cx: &mut Cx) -> Result<Vec<(Symbol, Value)>>

All key/value pairs, in backend order.

Source

fn len(&self, cx: &mut Cx) -> Result<usize>

Number of entries.

Source

fn clear(&self, cx: &mut Cx) -> Result<()>

Removes all entries.

Provided Methods§

Source

fn is_empty(&self, cx: &mut Cx) -> Result<bool>

Whether the table has no entries.

Source

fn as_table_expr(&self, cx: &mut Cx) -> Result<Expr>

Projects the table to an Expr::Map.

Source

fn table_eq(&self, cx: &mut Cx, other: &dyn Table) -> Result<bool>

Order-insensitive equality against another table’s entries.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§