mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
clone EdnItem
This commit is contained in:
parent
400fd9b6e9
commit
3dd8a7bc0d
8 changed files with 190 additions and 169 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue