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
use std::hash::{Hash, Hasher};
use super::{FunctionDeclaration, FunctionParameter};
use crate::{decl_engine::DeclRef, engine_threading::*, language::*, transform, type_system::*};
use sway_types::{ident::Ident, span::Span, Spanned};
#[derive(Debug, Clone)]
pub struct TraitDeclaration {
pub name: Ident,
pub(crate) type_parameters: Vec<TypeParameter>,
pub attributes: transform::AttributesMap,
pub interface_surface: Vec<TraitFn>,
pub methods: Vec<FunctionDeclaration>,
pub supertraits: Vec<Supertrait>,
pub visibility: Visibility,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct Supertrait {
pub name: CallPath,
pub decl_ref: Option<DeclRef>,
}
impl Spanned for Supertrait {
fn span(&self) -> Span {
self.name.span()
}
}
impl EqWithEngines for Supertrait {}
impl PartialEqWithEngines for Supertrait {
fn eq(&self, other: &Self, engines: Engines<'_>) -> bool {
self.name == other.name && self.decl_ref.eq(&other.decl_ref, engines)
}
}
impl HashWithEngines for Supertrait {
fn hash<H: Hasher>(&self, state: &mut H, engines: Engines<'_>) {
let Supertrait { name, decl_ref } = self;
name.hash(state);
decl_ref.hash(state, engines);
}
}
#[derive(Debug, Clone)]
pub struct TraitFn {
pub name: Ident,
pub attributes: transform::AttributesMap,
pub purity: Purity,
pub parameters: Vec<FunctionParameter>,
pub return_type: TypeInfo,
pub return_type_span: Span,
}