1use super::{AstNode, DocComment};
4use crate::source_tracking::fragment::Fragment;
5
6pub mod constant;
7pub mod enumeration;
8pub mod function;
9pub mod implementation;
10pub mod import;
11pub mod module;
12pub mod record;
13pub mod type_alias;
14pub mod union;
15
16#[derive(Debug, Clone, PartialEq)]
18pub struct Item {
19 pub docs: Vec<DocComment>,
21
22 pub visibility: Visibility,
24
25 pub kind: ItemKind,
27}
28
29impl Item {
30 pub fn is_public(&self) -> bool {
32 matches!(self.visibility, Visibility::Public(_))
33 }
34}
35
36impl AstNode for Item {
37 fn matching_source(&self) -> &Fragment {
38 self.kind.matching_source()
39 }
40}
41
42#[derive(Debug, Clone, PartialEq)]
44pub enum Visibility {
45 Private,
47 Public(Fragment),
49}
50
51#[derive(Debug, Clone, PartialEq)]
53#[allow(missing_docs)]
54pub enum ItemKind {
55 Import(import::ImportDecl),
56 Const(constant::ConstDecl),
57 TypeAlias(type_alias::TypeAlias),
58 Function(function::FunctionDecl),
59 Record(record::RecordDecl),
60 Enum(enumeration::EnumDecl),
61 Union(union::UnionDecl),
62 Impl(implementation::ImplDecl),
63 Module(module::ModuleDecl),
64}
65
66impl ItemKind {
67 pub fn matching_source(&self) -> &Fragment {
69 match self {
70 ItemKind::Import(decl) => &decl.matching_source,
71 ItemKind::Const(decl) => &decl.matching_source,
72 ItemKind::TypeAlias(decl) => &decl.matching_source,
73 ItemKind::Function(decl) => &decl.matching_source,
74 ItemKind::Record(decl) => &decl.matching_source,
75 ItemKind::Enum(decl) => &decl.matching_source,
76 ItemKind::Union(decl) => &decl.matching_source,
77 ItemKind::Impl(decl) => &decl.matching_source,
78 ItemKind::Module(decl) => &decl.matching_source,
79 }
80 }
81
82 pub const fn describe(&self) -> &'static str {
84 match self {
85 ItemKind::Import(_) => "import",
86 ItemKind::Const(_) => "constant",
87 ItemKind::TypeAlias(_) => "type alias",
88 ItemKind::Function(_) => "function",
89 ItemKind::Record(_) => "record",
90 ItemKind::Enum(_) => "enum",
91 ItemKind::Union(_) => "union",
92 ItemKind::Impl(_) => "impl block",
93 ItemKind::Module(_) => "module",
94 }
95 }
96}