refactor: into crates

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-04-30 20:27:55 +02:00
parent 469f28f65d
commit 14ef235dd9
14 changed files with 62 additions and 14 deletions

View File

@@ -0,0 +1,46 @@
use std::sync::{Arc, RwLock};
use crate::{engine::Engine, log::GraphItem};
#[derive(Clone)]
pub struct SharedEngine {
inner: Arc<RwLock<Engine>>,
}
impl From<Engine> for SharedEngine {
fn from(value: Engine) -> Self {
SharedEngine {
inner: Arc::new(RwLock::new(value)),
}
}
}
impl SharedEngine {
pub fn to_str(&self) -> anyhow::Result<String> {
self.inner.read().unwrap().to_str()
}
pub fn create_root(&self, root: &str) -> anyhow::Result<()> {
self.inner.write().unwrap().create_root(root)
}
pub fn create(&self, root: &str, path: &[&str], item: GraphItem) -> anyhow::Result<()> {
self.inner.write().unwrap().create(root, path, item)
}
pub fn get(&self, root: &str, path: &[&str]) -> Option<GraphItem> {
self.inner.read().unwrap().get(root, path).cloned()
}
pub fn section_move(
&self,
root: &str,
src_path: &[&str],
dest_path: &[&str],
) -> anyhow::Result<()> {
self.inner
.write()
.unwrap()
.section_move(root, src_path, dest_path)
}
}