Trait tau_engine::Array
source · pub trait Array {
// Required methods
fn iter(&self) -> Box<dyn Iterator<Item = Value<'_>> + '_>;
fn len(&self) -> usize;
}
Expand description
A data type that can be represented as an Array
.
This allows more complex array-like data types to be represented in a generic way for use as a
Value
.
Implementations
As long as the data type is considered array-like then Array
can be implemented on that
type. Below is a contrived example:
use tau_engine::{Array, Value};
// NOTE: Implements Iterator
#[derive(Clone)]
struct Counter {
count: usize,
}
impl Array for Counter {
fn iter(&self) -> Box<dyn Iterator<Item = Value<'_>> + '_> {
Box::new(self.clone().map(|v| Value::UInt(v as u64)))
}
fn len(&self) -> usize {
self.clone().count()
}
}