Vec impl
This commit is contained in:
parent
af3fa30986
commit
323a38db3a
32
src/lib.rs
32
src/lib.rs
|
|
@ -295,7 +295,37 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod build {}
|
impl<T> Value for Vec<T>
|
||||||
|
where
|
||||||
|
T: Value,
|
||||||
|
{
|
||||||
|
fn print(&self, w: &mut String) {
|
||||||
|
for v in self.iter() {
|
||||||
|
v.print(w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lookup(&self, name: &str) -> Option<&dyn Value> {
|
||||||
|
let idx: usize = name.parse().ok()?;
|
||||||
|
self.get(idx).map(|v| v as &dyn Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn has(&self) -> Option<&dyn Value> {
|
||||||
|
if self.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn if_(&self) -> bool {
|
||||||
|
self.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn for_(&self, index: usize) -> Option<&dyn Value> {
|
||||||
|
self.get(index).map(|v| v as &dyn Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Newt {
|
pub struct Newt {
|
||||||
ast: Ast,
|
ast: Ast,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue