sway_core/decl_engine/
interface_decl_id.rs

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
use crate::{
    decl_engine::*,
    engine_threading::{EqWithEngines, PartialEqWithEngines, PartialEqWithEnginesContext},
    language::{
        parsed::{AbiDeclaration, TraitDeclaration},
        ty,
    },
};

use super::{parsed_engine::ParsedDeclEngineGet, parsed_id::ParsedDeclId};

#[derive(Debug, Eq, PartialEq, Hash, Clone)]
pub enum ParsedInterfaceDeclId {
    Abi(ParsedDeclId<AbiDeclaration>),
    Trait(ParsedDeclId<TraitDeclaration>),
}

impl EqWithEngines for ParsedInterfaceDeclId {}
impl PartialEqWithEngines for ParsedInterfaceDeclId {
    fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool {
        let decl_engine = ctx.engines().pe();
        match (self, other) {
            (ParsedInterfaceDeclId::Abi(lhs), ParsedInterfaceDeclId::Abi(rhs)) => {
                decl_engine.get(lhs).eq(&decl_engine.get(rhs), ctx)
            }
            (ParsedInterfaceDeclId::Trait(lhs), ParsedInterfaceDeclId::Trait(rhs)) => {
                decl_engine.get(lhs).eq(&decl_engine.get(rhs), ctx)
            }
            _ => false,
        }
    }
}

impl From<ParsedDeclId<AbiDeclaration>> for ParsedInterfaceDeclId {
    fn from(id: ParsedDeclId<AbiDeclaration>) -> Self {
        Self::Abi(id)
    }
}

impl From<ParsedDeclId<TraitDeclaration>> for ParsedInterfaceDeclId {
    fn from(id: ParsedDeclId<TraitDeclaration>) -> Self {
        Self::Trait(id)
    }
}

#[derive(Debug, Eq, PartialEq, Hash, Clone)]
pub enum InterfaceDeclId {
    Abi(DeclId<ty::TyAbiDecl>),
    Trait(DeclId<ty::TyTraitDecl>),
}

impl From<DeclId<ty::TyAbiDecl>> for InterfaceDeclId {
    fn from(id: DeclId<ty::TyAbiDecl>) -> Self {
        Self::Abi(id)
    }
}

impl From<DeclId<ty::TyTraitDecl>> for InterfaceDeclId {
    fn from(id: DeclId<ty::TyTraitDecl>) -> Self {
        Self::Trait(id)
    }
}