temp commit

This commit is contained in:
2025-07-12 00:46:10 +02:00
parent 1868f1a506
commit fe89188c4b
60 changed files with 1536 additions and 709 deletions

View File

@@ -1,9 +1,11 @@
use std::borrow::Cow;
use std::num::NonZero;
use futures::FutureExt;
use futures::future::LocalBoxFuture;
use hashbrown::HashMap;
use orchid_base::interner::{Interner, Tok};
use orchid_base::pure_seq::pushed;
use crate::api;
use crate::system::SysCtx;
@@ -16,11 +18,58 @@ pub trait VirtFS: Send + Sync + 'static {
) -> LocalBoxFuture<'a, api::OrcResult<api::Loaded>>;
}
#[derive(Clone)]
pub struct DeclVmod(Cow<'static, [(&'static str, DeclFs)]>);
impl DeclVmod {
pub fn new(items: &'static [(&'static str, DeclFs)]) -> DeclVmod {
DeclVmod(Cow::Borrowed(items))
}
pub fn entry(
key: &'static str,
items: &'static [(&'static str, DeclFs)],
) -> (&'static str, DeclVmod) {
(key, DeclVmod(Cow::Borrowed(items)))
}
pub fn merge(&self, other: &Self) -> Result<Self, Vec<&'static str>> {
let mut items = Vec::new();
for (k, v1) in self.0.iter() {
items.push((*k, match other.0.iter().find(|(k2, _)| k == k2) {
Some((_, v2)) => v1.merge(v2).map_err(|e| pushed::<_, Vec<_>>(e, *k))?,
None => v1.clone(),
}));
}
for (k, v) in other.0.iter() {
if !items.iter().any(|(k2, _)| k2 == k) {
items.push((*k, v.clone()))
}
}
Ok(Self(Cow::Owned(items)))
}
pub async fn to_api_rec(
&self,
vfses: &mut HashMap<api::VfsId, &'static dyn VirtFS>,
i: &Interner,
) -> std::collections::HashMap<api::TStr, api::EagerVfs> {
let mut output = std::collections::HashMap::new();
for (k, v) in self.0.iter() {
output.insert(i.i::<String>(*k).await.to_api(), v.to_api_rec(vfses, i).boxed_local().await);
}
output
}
}
#[derive(Clone)]
pub enum DeclFs {
Lazy(&'static dyn VirtFS),
Mod(&'static [(&'static str, DeclFs)]),
Mod(DeclVmod),
}
impl DeclFs {
pub fn merge(&self, other: &Self) -> Result<Self, Vec<&'static str>> {
match (self, other) {
(Self::Mod(m1), Self::Mod(m2)) => Ok(Self::Mod(m1.merge(m2)?)),
(..) => Err(Vec::new()),
}
}
pub async fn to_api_rec(
&self,
vfses: &mut HashMap<api::VfsId, &'static dyn VirtFS>,
@@ -33,14 +82,7 @@ impl DeclFs {
vfses.insert(id, *fs);
api::EagerVfs::Lazy(id)
},
DeclFs::Mod(children) => {
let mut output = std::collections::HashMap::new();
for (k, v) in children.iter() {
output
.insert(i.i::<String>(*k).await.to_api(), v.to_api_rec(vfses, i).boxed_local().await);
}
api::EagerVfs::Eager(output)
},
DeclFs::Mod(m) => api::EagerVfs::Eager(m.to_api_rec(vfses, i).await),
}
}
}