communitas_core/
services.rs1use crate::{CrdtManager, CrdtResult};
11use std::sync::Arc;
12
13pub struct CoreServices {
15 crdt_manager: Arc<CrdtManager>,
16}
17
18impl CoreServices {
19 pub async fn bootstrap(db_path: impl AsRef<std::path::Path>) -> CrdtResult<Self> {
21 let crdt_manager = Arc::new(CrdtManager::new(db_path).await?);
22
23 Ok(Self { crdt_manager })
24 }
25
26 pub fn crdt_manager(&self) -> &Arc<CrdtManager> {
28 &self.crdt_manager
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35 use tempfile::tempdir;
36
37 #[tokio::test]
38 async fn test_bootstrap_services() {
39 let temp_dir = tempdir().unwrap();
40 let db_path = temp_dir.path().join("test.db");
41
42 let services = CoreServices::bootstrap(&db_path).await.unwrap();
43 assert!(Arc::strong_count(services.crdt_manager()) >= 1);
44 }
45}