Skip to main content

ListValue

Trait ListValue 

Source
pub trait ListValue: RuntimeObject {
    // Required methods
    fn is_empty(&self, cx: &mut Cx) -> Result<bool>;
    fn car(&self, cx: &mut Cx) -> Result<Option<Value>>;
    fn cdr(&self, cx: &mut Cx) -> Result<Option<Value>>;
    fn len(&self, cx: &mut Cx) -> Result<LengthResult>;

    // Provided methods
    fn len_cmp(&self, cx: &mut Cx, n: usize) -> Result<Ordering> { ... }
    fn get(&self, cx: &mut Cx, index: usize) -> Result<Option<Value>> { ... }
    fn for_each(
        &self,
        cx: &mut Cx,
        limit: Option<usize>,
        visit: &mut dyn FnMut(&Value),
    ) -> Result<()> { ... }
    fn to_vec(&self, cx: &mut Cx, limit: Option<usize>) -> Result<Vec<Value>> { ... }
    fn cdr_self(&self, _cx: &mut Cx) -> Result<Option<Value>> { ... }
    fn as_self_value(&self) -> Option<Value> { ... }
}
Expand description

Shared behaviour for every list backend.

Required Methods§

Source

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

Whether the list has no elements.

Source

fn car(&self, cx: &mut Cx) -> Result<Option<Value>>

The first element, or Ok(None) when empty.

Source

fn cdr(&self, cx: &mut Cx) -> Result<Option<Value>>

The tail list after the first element, or Ok(None) when empty.

Source

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

The length, finite or LengthResult::Unknown for endless lists.

Provided Methods§

Source

fn len_cmp(&self, cx: &mut Cx, n: usize) -> Result<Ordering>

Compares the spine length against n without fully forcing the list.

Source

fn get(&self, cx: &mut Cx, index: usize) -> Result<Option<Value>>

The element at index, or Ok(None) when out of range.

Source

fn for_each( &self, cx: &mut Cx, limit: Option<usize>, visit: &mut dyn FnMut(&Value), ) -> Result<()>

Visits up to limit elements in order, walking the list spine.

Source

fn to_vec(&self, cx: &mut Cx, limit: Option<usize>) -> Result<Vec<Value>>

Collects up to limit elements into a vector.

Source

fn cdr_self(&self, _cx: &mut Cx) -> Result<Option<Value>>

The value to start spine walks from; the receiver itself by default.

Source

fn as_self_value(&self) -> Option<Value>

The receiver re-wrapped as a Value, when it can produce one.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§