microcad_lang/syntax/function/
function_definition.rs1use crate::{src_ref::*, syntax::*};
7
8#[derive(Clone)]
10pub struct FunctionDefinition {
11 pub doc: Option<DocBlock>,
13 pub visibility: Visibility,
15 pub id: Identifier,
17 pub signature: FunctionSignature,
19 pub body: Body,
21}
22
23impl SrcReferrer for FunctionDefinition {
24 fn src_ref(&self) -> SrcRef {
25 self.id.src_ref()
26 }
27}
28
29impl TreeDisplay for FunctionDefinition {
30 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
31 writeln!(f, "{:depth$}FunctionDefinition '{}':", "", self.id)?;
32 depth.indent();
33 if let Some(doc) = &self.doc {
34 doc.tree_print(f, depth)?;
35 }
36 writeln!(f, "{:depth$}Signature:", "")?;
37 self.signature.tree_print(f, depth)?;
38 writeln!(f, "{:depth$}Body:", "")?;
39 self.body.tree_print(f, depth)
40 }
41}
42
43impl std::fmt::Display for FunctionDefinition {
44 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45 write!(f, "fn {}{}", self.id, self.signature)
46 }
47}
48
49impl std::fmt::Debug for FunctionDefinition {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 write!(f, "fn {:?}{:?}", self.id, self.signature)
52 }
53}
54
55impl Doc for FunctionDefinition {
56 fn doc(&self) -> Option<DocBlock> {
57 self.doc.clone()
58 }
59}