use compact_str::CompactString;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct DataModel {
pub items: Vec<DataItem>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct DataItem {
pub id: CompactString,
pub expr: Option<CompactString>,
pub src: Option<CompactString>,
}
impl DataModel {
pub fn new() -> Self {
Self { items: Vec::new() }
}
pub fn with_item(mut self, item: DataItem) -> Self {
self.items.push(item);
self
}
}
impl DataItem {
pub fn new(id: impl Into<CompactString>) -> Self {
Self {
id: id.into(),
expr: None,
src: None,
}
}
pub fn with_expr(id: impl Into<CompactString>, expr: impl Into<CompactString>) -> Self {
Self {
id: id.into(),
expr: Some(expr.into()),
src: None,
}
}
}