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
use super::{Attribute, Identifier, Span};

/// An AST node with a span.
pub trait WithSpan {
    /// The span of the node.
    fn span(&self) -> Span;
}

/// An AST node with a name (from the identifier).
pub trait WithName {
    /// The name of the item.
    fn name(&self) -> &str;
}

/// An AST node with an identifier.
pub trait WithIdentifier {
    /// The identifier.
    fn identifier(&self) -> &Identifier;
}

/// An AST node with attributes.
pub trait WithAttributes {
    /// The attributes.
    fn attributes(&self) -> &[Attribute];
}

/// An AST node with documentation.
pub trait WithDocumentation {
    /// The documentation string, if defined.
    fn documentation(&self) -> Option<&str>;
}

/// An AST node with a name.
impl<T> WithName for T
where
    T: WithIdentifier,
{
    /// The name token of the node.
    fn name(&self) -> &str {
        &self.identifier().name
    }
}