feat: usable?

This commit is contained in:
2025-05-05 11:31:46 +08:00
parent eea4a4ce9f
commit b9dcc83c39
24 changed files with 688 additions and 244 deletions

View File

@@ -1,4 +1,4 @@
use std::fmt::{Debug, Formatter, Result as FmtResult};
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
use derive_more::{Constructor, IsVariant, Unwrap};
use rpds::{HashTrieMapSync, VectorSync};
@@ -24,11 +24,30 @@ impl Debug for AttrSet {
}
}
impl Display for AttrSet {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(f, "{{ ")?;
for (k, v) in self.data.iter() {
write!(f, "{k} = {v}; ")?;
}
write!(f, "}}")
}
}
#[derive(Constructor, Clone, Debug, PartialEq)]
pub struct List {
data: VectorSync<Value>,
}
impl Display for List {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(f, "[ ")?;
for v in self.data.iter() {
write!(f, "{v} ")?;
}
write!(f, "]")
}
}
#[derive(IsVariant, Unwrap, Clone, Debug, PartialEq)]
pub enum Value {
@@ -41,3 +60,19 @@ pub enum Value {
PrimOp(&'static str),
PartialPrimOp(&'static str),
}
impl Display for Value {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
use Value::*;
match self {
Const(x) => write!(f, "{x}"),
AttrSet(x) => write!(f, "{x}"),
List(x) => write!(f, "{x}"),
Catchable(x) => write!(f, "{x}"),
Thunk => write!(f, "<CODE>"),
Func => write!(f, "<LAMBDA>"),
PrimOp(x) => write!(f, "<PRIMOP {x}>"),
PartialPrimOp(x) => write!(f, "<PARTIAL PRIMOP {x}>"),
}
}
}