microcad_lang/syntax/function/
function_signature.rs1use crate::{src_ref::*, syntax::*};
7
8#[derive(Clone, Debug)]
10pub struct FunctionSignature {
11 pub parameters: ParameterList,
13 pub return_type: Option<TypeAnnotation>,
15 pub src_ref: SrcRef,
17}
18
19impl SrcReferrer for FunctionSignature {
20 fn src_ref(&self) -> SrcRef {
21 self.src_ref.clone()
22 }
23}
24
25impl FunctionSignature {
26 pub fn parameter_by_name(&self, name: &Identifier) -> Option<&Parameter> {
28 self.parameters.iter().find(|arg| arg.id == *name)
29 }
30}
31
32impl TreeDisplay for FunctionSignature {
33 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
34 writeln!(f, "{:depth$}Parameters:", "")?;
35 depth.indent();
36 self.parameters.tree_print(f, depth)?;
37 if let Some(return_type) = &self.return_type {
38 writeln!(f, "{:depth$}Return:", "")?;
39 return_type.tree_print(f, depth)?;
40 };
41 Ok(())
42 }
43}