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