mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
serialize edn via display trait
This commit is contained in:
parent
23fe9f0949
commit
08184f9906
3 changed files with 20 additions and 6 deletions
|
|
@ -12,15 +12,28 @@ impl<T> Default for EdnItem<T> {
|
||||||
Self::Nil
|
Self::Nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl<T: Debug + Display> Display for EdnItem<T> {
|
||||||
|
fn fmt (&self, f: &mut Formatter<'_>) -> Result<(), FormatError> {
|
||||||
|
use EdnItem::*;
|
||||||
|
use itertools::join;
|
||||||
|
match self {
|
||||||
|
Nil => write!(f, ""),
|
||||||
|
Num(u) => write!(f, "{u}"),
|
||||||
|
Sym(u) => write!(f, "{u}"),
|
||||||
|
Key(u) => write!(f, "{u}"),
|
||||||
|
Exp(e) => write!(f, "({})", join(e.iter().map(|i|format!("{}", i)), " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
impl<T: Debug> Debug for EdnItem<T> {
|
impl<T: Debug> Debug for EdnItem<T> {
|
||||||
fn fmt (&self, f: &mut Formatter<'_>) -> Result<(), FormatError> {
|
fn fmt (&self, f: &mut Formatter<'_>) -> Result<(), FormatError> {
|
||||||
use EdnItem::*;
|
use EdnItem::*;
|
||||||
match self {
|
match self {
|
||||||
Nil => write!(f, "Nil"),
|
Nil => write!(f, "(nil)"),
|
||||||
Num(u) => write!(f, "Num({u})"),
|
Num(u) => write!(f, "(num {u})"),
|
||||||
Sym(u) => write!(f, "Sym({u:?})"),
|
Sym(u) => write!(f, "(sym {u:?})"),
|
||||||
Key(u) => write!(f, "Key({u:?})"),
|
Key(u) => write!(f, "(key {u:?})"),
|
||||||
Exp(e) => write!(f, "Exp({})",
|
Exp(e) => write!(f, "(exp {})",
|
||||||
itertools::join(e.iter().map(|i|format!("{:?}", i)), ","))
|
itertools::join(e.iter().map(|i|format!("{:?}", i)), ","))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
#![feature(impl_trait_in_fn_trait_return)]
|
#![feature(impl_trait_in_fn_trait_return)]
|
||||||
|
|
||||||
pub(crate) use std::{fmt::{Debug, Formatter, Error as FormatError}};
|
pub(crate) use std::{fmt::{Debug, Display, Formatter, Error as FormatError}};
|
||||||
|
|
||||||
mod edn_error; pub use self::edn_error::*;
|
mod edn_error; pub use self::edn_error::*;
|
||||||
mod edn_item; pub use self::edn_item::*;
|
mod edn_item; pub use self::edn_item::*;
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,7 @@ impl<E: Output, A: Content<E>, B: Content<E>> BspAreas<E, A, B> for Bsp<E, A, B>
|
||||||
impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for Bsp<E, RenderBox<'a, E>, RenderBox<'a, E>> {
|
impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for Bsp<E, RenderBox<'a, E>, RenderBox<'a, E>> {
|
||||||
fn try_from_edn (s: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option<Self> {
|
fn try_from_edn (s: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option<Self> {
|
||||||
use EdnItem::*;
|
use EdnItem::*;
|
||||||
|
panic!("({head} {} {})", tail[0], tail[1]);
|
||||||
Some(match (head, tail) {
|
Some(match (head, tail) {
|
||||||
(Key("bsp/n"), [a, b]) => Self::n(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
|
(Key("bsp/n"), [a, b]) => Self::n(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
|
||||||
(Key("bsp/s"), [a, b]) => Self::s(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
|
(Key("bsp/s"), [a, b]) => Self::s(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue