microcad_lang/syntax/use/
use_statement.rs1use microcad_lang_base::{SrcRef, SrcReferrer, TreeDisplay, TreeState};
7
8use crate::syntax::*;
9
10#[derive(Clone)]
17pub struct UseStatement {
18 pub keyword_ref: SrcRef,
20 pub visibility: Visibility,
22 pub decl: UseDeclaration,
24 pub src_ref: SrcRef,
26}
27
28impl SrcReferrer for UseStatement {
29 fn src_ref(&self) -> SrcRef {
30 self.src_ref.clone()
31 }
32}
33
34impl std::fmt::Display for UseStatement {
35 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
36 match &self.visibility {
37 Visibility::Private | Visibility::PrivateUse(_) => write!(f, "use ")?,
38 Visibility::Public => write!(f, "pub use ")?,
39 Visibility::Deleted => unreachable!(),
40 }
41 write!(f, "{}", self.decl)?;
42 Ok(())
43 }
44}
45
46impl std::fmt::Debug for UseStatement {
47 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
48 match &self.visibility {
49 Visibility::Private | Visibility::PrivateUse(_) => write!(f, "use ")?,
50 Visibility::Public => write!(f, "pub use ")?,
51 Visibility::Deleted => unreachable!(),
52 }
53 write!(f, "{:?}", self.decl)?;
54 Ok(())
55 }
56}
57
58impl TreeDisplay for UseStatement {
59 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
60 writeln!(f, "{:depth$}UseStatement", "")?;
61 depth.indent();
62 self.decl.tree_print(f, depth)
63 }
64}