Starts synchronous block interface

This commit is contained in:
2026-03-19 15:28:31 +01:00
parent f727c119b8
commit 2baee8d28b
11 changed files with 348 additions and 260 deletions

View File

@ -17,7 +17,51 @@ pub struct Tag
// TODO: Make it such that when a tag is duplicated, the data seems to be too:
// When adding on a duplicate, it should not replicate on others, but without
// requiring a deep copy.
pub data: Arc<Mutex<HashMap<String, Box<dyn Any>>>>,
pub data: Arc<Mutex<HashMap<String, Arc<dyn Any + Send + Sync>>>>,
}
pub trait TagValue: Clone {}
impl<T> TagValue for T where T: Clone {}
pub trait TagMergable<T>
{
fn merge(&self, other: &T) -> Self;
}
impl TagMergable<Tag> for Tag
{
fn merge(&self, other: &Self) -> Self
{
// TODO: More performant merge
let mut new = other.clone();
new.position = self.position;
{
let mut data_locked = new.data.lock().unwrap();
for (k, v) in self.data.lock().unwrap().iter()
{
data_locked.insert(k.clone(), v.clone());
}
}
new
}
}
impl TagMergable<Option<Tag>> for Option<Tag>
{
fn merge(&self, other: &Self) -> Self
{
match self
{
Some(first) => match other
{
Some(other) => Some(first.merge(other)),
None => Some(first.clone()),
},
None => other.clone(),
}
}
}
/// Represents a data, with a potential tag attached to it.