feat: at least it compiles, right?

This commit is contained in:
2025-06-12 20:12:31 +08:00
parent 7293cb9f75
commit 49255948ff
22 changed files with 383 additions and 251 deletions

View File

@@ -1,8 +1,8 @@
use std::ops::Deref;
use std::rc::Rc;
use ecow::EcoString;
use derive_more::Constructor;
use ecow::EcoString;
use hashbrown::{HashMap, HashSet};
use itertools::Itertools;
@@ -50,30 +50,39 @@ impl AttrSet {
self.data.insert(sym, val);
}
pub fn select(&self, mut path: impl DoubleEndedIterator<Item = Result<EcoString>>) -> Result<Value> {
// .ok_or_else(|| Error::EvalError())),
pub fn select(
&self,
mut path: impl DoubleEndedIterator<Item = Result<EcoString>>,
) -> Result<Value> {
// .ok_or_else(|| Error::EvalError())),
let mut data = &self.data;
let last = path.nth_back(0).unwrap();
for item in path {
let item = item?;
let Some(Value::AttrSet(attrs)) = data.get(&item) else {
return Err(Error::EvalError(format!("{} not found", Symbol::from(item))))
let Some(Value::AttrSet(attrs)) = data.get(&item) else {
return Err(Error::EvalError(format!(
"{} not found",
Symbol::from(item)
)));
};
data = attrs.as_inner();
}
let last = last?;
data.get(&last).cloned().ok_or_else(|| Error::EvalError(format!("{} not found", Symbol::from(last))))
data.get(&last)
.cloned()
.ok_or_else(|| Error::EvalError(format!("{} not found", Symbol::from(last))))
}
pub fn has_attr(&self, path: impl IntoIterator<Item = Result<EcoString>>) -> Result<bool> {
pub fn has_attr(&self, mut path: impl DoubleEndedIterator<Item = Result<EcoString>>) -> Result<bool> {
let mut data = &self.data;
let last = path.nth_back(0).unwrap();
for item in path {
let Some(Value::AttrSet(attrs)) = data.get(&item?) else {
return Ok(false)
let Some(Value::AttrSet(attrs)) = data.get(&item?) else {
return Ok(false);
};
data = attrs.as_inner();
}
Ok(true)
Ok(data.get(&last?).is_some())
}
pub fn update(&mut self, other: &AttrSet) {