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
use crate::{engine_threading::*, type_system::*};
use std::{fmt, hash::Hasher};
use sway_types::{Span, Spanned};
#[derive(Debug, Clone)]
pub struct TypeArgument {
pub type_id: TypeId,
pub initial_type_id: TypeId,
pub span: Span,
}
impl Spanned for TypeArgument {
fn span(&self) -> Span {
self.span.clone()
}
}
impl HashWithEngines for TypeArgument {
fn hash<H: Hasher>(&self, state: &mut H, type_engine: &TypeEngine) {
type_engine.get(self.type_id).hash(state, type_engine);
}
}
impl EqWithEngines for TypeArgument {}
impl PartialEqWithEngines for TypeArgument {
fn eq(&self, other: &Self, engines: Engines<'_>) -> bool {
let type_engine = engines.te();
type_engine
.get(self.type_id)
.eq(&type_engine.get(other.type_id), engines)
}
}
impl OrdWithEngines for TypeArgument {
fn cmp(&self, rhs: &Self, _: &TypeEngine) -> std::cmp::Ordering {
self.type_id
.cmp(&rhs.type_id)
.then_with(|| self.initial_type_id.cmp(&rhs.initial_type_id))
}
}
impl DisplayWithEngines for TypeArgument {
fn fmt(&self, f: &mut fmt::Formatter<'_>, engines: Engines<'_>) -> fmt::Result {
write!(f, "{}", engines.help_out(engines.te().get(self.type_id)))
}
}
impl From<&TypeParameter> for TypeArgument {
fn from(type_param: &TypeParameter) -> Self {
TypeArgument {
type_id: type_param.type_id,
initial_type_id: type_param.initial_type_id,
span: type_param.name_ident.span(),
}
}
}
impl TypeArgument {
pub fn json_abi_str(&self, type_engine: &TypeEngine) -> String {
type_engine.get(self.type_id).json_abi_str(type_engine)
}
}
impl ReplaceSelfType for TypeArgument {
fn replace_self_type(&mut self, engines: Engines<'_>, self_type: TypeId) {
self.type_id.replace_self_type(engines, self_type);
}
}
impl SubstTypes for TypeArgument {
fn subst_inner(&mut self, type_mapping: &TypeSubstMap, engines: Engines<'_>) {
self.type_id.subst(type_mapping, engines);
}
}