1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! A definition site: what a name in one unit declares.
use std::sync::Arc;
use serde::{Deserialize, Serialize};
use crate::Language;
use super::id::{DefinitionId, ResolutionUnitId};
use super::span::SourceSpan;
/// The closed vocabulary of definitions a report emits.
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(rename_all = "snake_case")]
pub enum SymbolKind {
/// A module.
Module,
/// A free or associated function.
Function,
/// A method reached through a receiver.
Method,
/// A struct.
Struct,
/// An enum.
Enum,
/// A union.
Union,
/// A trait.
Trait,
/// A type alias.
TypeAlias,
/// A constant.
Constant,
/// A static.
Static,
}
/// One definition site inside one resolution unit.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct SymbolDefinition {
id: DefinitionId,
unit: ResolutionUnitId,
language: Language,
kind: SymbolKind,
name: Arc<str>,
span: SourceSpan,
parent: Option<DefinitionId>,
}
impl SymbolDefinition {
pub(crate) fn new(
id: DefinitionId,
unit: ResolutionUnitId,
language: Language,
kind: SymbolKind,
name: Arc<str>,
span: SourceSpan,
parent: Option<DefinitionId>,
) -> Self {
Self {
id,
unit,
language,
kind,
name,
span,
parent,
}
}
/// This definition's identifier.
pub fn id(&self) -> DefinitionId {
self.id
}
/// The unit this definition is declared in.
pub fn unit(&self) -> ResolutionUnitId {
self.unit
}
/// The language of the unit this definition belongs to.
pub fn language(&self) -> Language {
self.language
}
/// What kind of definition this is.
pub fn kind(&self) -> SymbolKind {
self.kind
}
/// The declared name.
pub fn name(&self) -> &str {
&self.name
}
/// Where the definition sits in the snapshotted source.
pub fn span(&self) -> &SourceSpan {
&self.span
}
/// The span, for a decoder interning the paths it just allocated.
pub(super) fn span_mut(&mut self) -> &mut SourceSpan {
&mut self.span
}
/// The definition that lexically owns this one, in the same unit.
pub fn parent(&self) -> Option<DefinitionId> {
self.parent
}
}