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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
use crate::{Hash, InstFnNameHash, IntoTypeHash, Item};
use std::cmp;
use std::fmt;
use std::hash;

/// A built in instance function.
#[derive(Debug, Clone, Copy)]
pub struct Protocol {
    /// The name of the builtin function.
    pub name: &'static str,
    /// The hash of the builtin function.
    pub hash: Hash,
}

impl InstFnNameHash for Protocol {
    fn inst_fn_name_hash(self) -> Hash {
        self.hash
    }

    fn into_name(self) -> String {
        String::from(self.name)
    }
}

impl IntoTypeHash for Protocol {
    fn into_type_hash(self) -> Hash {
        self.hash
    }

    fn into_item(self) -> Item {
        Item::with_item(&[self.name])
    }
}

impl std::ops::Deref for Protocol {
    type Target = Hash;

    fn deref(&self) -> &Self::Target {
        &self.hash
    }
}

impl fmt::Display for Protocol {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.name)
    }
}

impl cmp::PartialEq for Protocol {
    fn eq(&self, other: &Self) -> bool {
        self.hash.eq(&other.hash)
    }
}

impl cmp::Eq for Protocol {}

impl hash::Hash for Protocol {
    fn hash<H: hash::Hasher>(&self, state: &mut H) {
        self.hash.hash(state)
    }
}

impl Protocol {
    /// Check two types for equality.
    pub const EQ: Protocol = Protocol {
        name: "eq",
        hash: Hash::new(0x418f5becbf885806),
    };

    /// The function to access a field.
    pub const GET: Protocol = Protocol {
        name: "get",
        hash: Hash::new(0x504007af1a8485a4),
    };

    /// The function to set a field.
    pub const SET: Protocol = Protocol {
        name: "set",
        hash: Hash::new(0x7d13d47fd8efef5a),
    };

    /// The function to access an index.
    pub const INDEX_GET: Protocol = Protocol {
        name: "index_get",
        hash: Hash::new(0xadb5b27e2a4d2dec),
    };

    /// The function to set an index.
    pub const INDEX_SET: Protocol = Protocol {
        name: "index_set",
        hash: Hash::new(0x162943f7bd03ad36),
    };

    /// The function to implement for the addition operation.
    pub const ADD: Protocol = Protocol {
        name: "+",
        hash: Hash::new(0xe4ecf51fa0bf1076),
    };

    /// The function to implement for the addition assign operation.
    pub const ADD_ASSIGN: Protocol = Protocol {
        name: "+=",
        hash: Hash::new(0x42451ccb0a2071a9),
    };

    /// The function to implement for the subtraction operation.
    pub const SUB: Protocol = Protocol {
        name: "-",
        hash: Hash::new(0x6fa86a5f18d0bf71),
    };

    /// The function to implement for the subtraction assign operation.
    pub const SUB_ASSIGN: Protocol = Protocol {
        name: "-=",
        hash: Hash::new(0x5939bb56a1415284),
    };

    /// The function to implement for the multiply operation.
    pub const MUL: Protocol = Protocol {
        name: "*",
        hash: Hash::new(0xb09e99dc94091d1c),
    };

    /// The function to implement for the multiply assign operation.
    pub const MUL_ASSIGN: Protocol = Protocol {
        name: "*=",
        hash: Hash::new(0x29a54b727f980ebf),
    };

    /// The function to implement for the division operation.
    pub const DIV: Protocol = Protocol {
        name: "/",
        hash: Hash::new(0xf26d6eea1afca6e8),
    };

    /// The function to implement for the division assign operation.
    pub const DIV_ASSIGN: Protocol = Protocol {
        name: "/=",
        hash: Hash::new(0x4dd087a8281c04e6),
    };

    /// The function to implement for the remainder operation.
    pub const REM: Protocol = Protocol {
        name: "%",
        hash: Hash::new(0x5c6293639c74e671),
    };

    /// The function to implement for the remainder assign operation.
    pub const REM_ASSIGN: Protocol = Protocol {
        name: "%=",
        hash: Hash::new(0x3a8695980e77baf4),
    };

    /// The function to implement for the bitwise and operation.
    pub const BIT_AND: Protocol = Protocol {
        name: "&",
        hash: Hash::new(0x0e11f20d940eebe8),
    };

    /// The function to implement for the bitwise and assign operation.
    pub const BIT_AND_ASSIGN: Protocol = Protocol {
        name: "&=",
        hash: Hash::new(0x95cb1ba235dfb5ec),
    };

    /// The function to implement for the bitwise xor operation.
    pub const BIT_XOR: Protocol = Protocol {
        name: "^",
        hash: Hash::new(0xa3099c54e1de4cbf),
    };

    /// The function to implement for the bitwise xor assign operation.
    pub const BIT_XOR_ASSIGN: Protocol = Protocol {
        name: "^=",
        hash: Hash::new(0x01fa9706738f9867),
    };

    /// The function to implement for the bitwise or operation.
    pub const BIT_OR: Protocol = Protocol {
        name: "|",
        hash: Hash::new(0x05010afceb4a03d0),
    };

    /// The function to implement for the bitwise xor assign operation.
    pub const BIT_OR_ASSIGN: Protocol = Protocol {
        name: "|=",
        hash: Hash::new(0x606d79ff1750a7ec),
    };

    /// The function to implement for the bitwise shift left operation.
    pub const SHL: Protocol = Protocol {
        name: "<<",
        hash: Hash::new(0x6845f7d0cc9e002d),
    };

    /// The function to implement for the bitwise shift left assign operation.
    pub const SHL_ASSIGN: Protocol = Protocol {
        name: "<<=",
        hash: Hash::new(0xdc4702d0307ba27b),
    };

    /// The function to implement for the bitwise shift right operation.
    pub const SHR: Protocol = Protocol {
        name: ">>",
        hash: Hash::new(0x6b485e8e6e58fbc8),
    };

    /// The function to implement for the bitwise shift right assign operation.
    pub const SHR_ASSIGN: Protocol = Protocol {
        name: ">>=",
        hash: Hash::new(0x61ff7c46ff00e74a),
    };

    /// Protocol function used by template strings.
    pub const STRING_DISPLAY: Protocol = Protocol {
        name: "string_display",
        hash: Hash::new(0x811b62957ea9d9f9),
    };

    /// Protocol function used by custom debug impls.
    pub const STRING_DEBUG: Protocol = Protocol {
        name: "string_debug",
        hash: Hash::new(0x4064e3867aaa0717),
    };

    /// Function used to convert an argument into an iterator.
    pub const INTO_ITER: Protocol = Protocol {
        name: "into_iter",
        hash: Hash::new(0x15a85c8d774b4065),
    };

    /// The function to call to continue iteration.
    pub const NEXT: Protocol = Protocol {
        name: "next",
        hash: Hash::new(0xc3cde069de2ba320),
    };

    /// Function used to convert an argument into a future.
    pub const INTO_FUTURE: Protocol = Protocol {
        name: "into_future",
        hash: Hash::new(0x596e6428deabfda2),
    };

    /// Function used to convert an argument into a future.
    pub const INTO_TYPE_NAME: Protocol = Protocol {
        name: "into_type_name",
        hash: Hash::new(0xbffd08b816c24682),
    };
}