moduforge_runtime/helpers/
create_doc.rs1use std::sync::Arc;
2
3use moduforge_model::{node_pool::NodePool, schema::Schema};
4
5use crate::types::Content;
6
7pub async fn create_doc(
9 schema: &Schema,
10 content: &Content,
11) -> Option<Arc<NodePool>> {
12 let doc = match content {
13 Content::NodePool(node_pool) => Some(Arc::new(node_pool.clone())),
14 Content::None => None,
15 Content::NodePoolFn(node_pool_fn_trait) => {
16 let node_pool = node_pool_fn_trait.create(schema).await;
17 Some(Arc::new(node_pool))
18 },
19 };
20 if let Some(doc) = &doc {
21 if let Err(err) = doc.validate_hierarchy() {
22 panic!("{}", err);
23 }
24 }
25 doc
26}