clone EdnItem

This commit is contained in:
🪞👃🪞 2025-01-05 22:52:35 +01:00
parent 400fd9b6e9
commit 3dd8a7bc0d
8 changed files with 190 additions and 169 deletions

View file

@ -38,6 +38,18 @@ impl<T: PartialEq> PartialEq for EdnItem<T> {
}
}
}
impl EdnItem<&str> {
pub fn clone (&self) -> EdnItem<String> {
use EdnItem::*;
match self {
Nil => Nil,
Num(u) => Num(*u),
Sym(u) => Sym(u.to_string()),
Key(u) => Key(u.to_string()),
Exp(e) => Exp(e.iter().map(|i|i.clone()).collect()),
}
}
}
impl<T: AsRef<str> + PartialEq + Default + Clone + std::fmt::Debug> EdnItem<T> {
pub fn to_ref (&self) -> EdnItem<&str> {
match self {

View file

@ -26,12 +26,15 @@ pub enum EdnView<E: Output, T: EdnViewData<E>> {
}
impl<E: Output, T: EdnViewData<E>> EdnView<E, T> {
pub fn new (state: T, source: &str) -> Self {
pub fn from_source (state: T, source: &str) -> Self {
match EdnItem::read_one(&source) {
Ok((layout, _)) => Self::Ok(state, layout),
Err(error) => Self::Err(format!("{error}"))
}
}
pub fn from_items (state: T, items: &[EdnItem<&str>]) -> Self {
Self::Ok(state, EdnItem::Exp(items.iter().map(|i|(*i).clone()).collect()))
}
}
impl<E: Output, T: EdnViewData<E> + Send + Sync> Content<E> for EdnView<E, T> {