use crate::error::Result;
use crate::template::{TModel, TemplateSequenceModel};
#[derive(Default, Clone)]
pub struct SimpleList {
items: Vec<TModel>,
}
impl SimpleList {
pub fn new() -> Self {
SimpleList { items: Vec::new() }
}
pub fn add(&mut self, item: TModel) {
self.items.push(item);
}
}
impl TemplateSequenceModel for SimpleList {
fn get(&self, index: usize) -> Result<TModel> {
self.items
.get(index)
.cloned()
.ok_or_else(|| crate::error::TemplateError::misc("index out of bounds".to_string()))
}
fn size(&self) -> Result<usize> {
Ok(self.items.len())
}
}