reactive_graph_generator_documentation/generator/
mod.rs1pub mod component_type_id_container;
2pub mod extension_container;
3pub mod property_type;
4pub mod property_type_container;
5pub mod type_definition;
6pub mod type_definition_json_schema;
7pub mod type_description;
8pub mod variables_container;
9
10use markdown_builder::Markdown;
11use std::fmt::Display;
12use std::fmt::Formatter;
13use std::sync::Arc;
14use std::sync::RwLock;
15
16pub struct TypedMarkdownDocumentation<TY> {
17 pub(crate) ty: TY,
18 pub(crate) document: Arc<RwLock<Markdown>>,
19}
20
21impl<TY> TypedMarkdownDocumentation<TY>
22where
23 TY: Clone,
24{
25 pub fn new(ty: TY) -> Self {
26 Self {
27 ty,
28 document: Arc::new(RwLock::new(Markdown::new())),
29 }
30 }
31
32 pub fn new_with_document(ty: TY, document: Arc<RwLock<Markdown>>) -> Self {
33 Self { ty, document }
34 }
35}
36
37impl<TY> Display for TypedMarkdownDocumentation<TY> {
38 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
39 let document = self.document.read().unwrap();
40 write!(f, "{}", document.render())
41 }
42}
43
44pub struct MarkdownDocumentation(Arc<RwLock<Markdown>>);
45
46impl<TY> From<TypedMarkdownDocumentation<TY>> for MarkdownDocumentation {
47 fn from(markdown_documentation: TypedMarkdownDocumentation<TY>) -> Self {
48 MarkdownDocumentation(markdown_documentation.document)
49 }
50}
51
52impl<TY> From<&TypedMarkdownDocumentation<TY>> for MarkdownDocumentation {
53 fn from(markdown_documentation: &TypedMarkdownDocumentation<TY>) -> Self {
54 MarkdownDocumentation(markdown_documentation.document.clone())
55 }
56}
57
58impl Display for MarkdownDocumentation {
59 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
60 let document = self.0.read().unwrap();
61 write!(f, "{}", document.render())
62 }
63}