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
use super::*;

mod display;

/// The kind of trait
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TraitKind {
    /// `trait`
    Trait,
    /// `interface`
    Interface,
}

/// `trait name: Debug {}`
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TraitDeclaration {
    /// The kind of the trait
    pub kind: TraitKind,
    /// The name of the trait
    pub name: IdentifierNode,
    /// The generic parameters
    pub generics: Option<ParametersList>,
    /// `trait A: Debug { }`, the trait bounds
    pub implements: Option<ExpressionKind>,
    /// the needed fields(zero parameter method, get + set)
    pub body: Vec<TraitTerm>,
}

/// `extends path::A: Debug {}`
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendsStatement {
    /// `extends A: Debug { }`, the trait bounds
    pub implements: Option<ExpressionKind>,
    /// The additional methods
    pub body: Vec<TraitTerm>,
}

/// The valid terms in a trait body.
#[derive(Clone, PartialEq, Eq, Hash, From)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TraitTerm {
    /// `@expand {}`
    Macro(ProceduralNode),
    /// `field: Type = default`
    Field(FieldDeclaration),
    /// `method()`
    Method(MethodDeclaration),
}