1use crate::{Hash, InstFnNameHash, IntoTypeHash, Item};
2use std::cmp;
3use std::fmt;
4use std::hash;
5
6#[derive(Debug, Clone, Copy)]
8pub struct Protocol {
9 pub name: &'static str,
11 pub hash: Hash,
13}
14
15impl InstFnNameHash for Protocol {
16 fn inst_fn_name_hash(self) -> Hash {
17 self.hash
18 }
19
20 fn into_name(self) -> String {
21 String::from(self.name)
22 }
23}
24
25impl IntoTypeHash for Protocol {
26 fn into_type_hash(self) -> Hash {
27 self.hash
28 }
29
30 fn into_item(self) -> Item {
31 Item::with_item(&[self.name])
32 }
33}
34
35impl std::ops::Deref for Protocol {
36 type Target = Hash;
37
38 fn deref(&self) -> &Self::Target {
39 &self.hash
40 }
41}
42
43impl fmt::Display for Protocol {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 write!(f, "{}", self.name)
46 }
47}
48
49impl cmp::PartialEq for Protocol {
50 fn eq(&self, other: &Self) -> bool {
51 self.hash.eq(&other.hash)
52 }
53}
54
55impl cmp::Eq for Protocol {}
56
57impl hash::Hash for Protocol {
58 fn hash<H: hash::Hasher>(&self, state: &mut H) {
59 self.hash.hash(state)
60 }
61}
62
63impl Protocol {
64 pub const EQ: Protocol = Protocol {
66 name: "eq",
67 hash: Hash::new(0x418f5becbf885806),
68 };
69
70 pub const GET: Protocol = Protocol {
72 name: "get",
73 hash: Hash::new(0x504007af1a8485a4),
74 };
75
76 pub const SET: Protocol = Protocol {
78 name: "set",
79 hash: Hash::new(0x7d13d47fd8efef5a),
80 };
81
82 pub const INDEX_GET: Protocol = Protocol {
84 name: "index_get",
85 hash: Hash::new(0xadb5b27e2a4d2dec),
86 };
87
88 pub const INDEX_SET: Protocol = Protocol {
90 name: "index_set",
91 hash: Hash::new(0x162943f7bd03ad36),
92 };
93
94 pub const ADD: Protocol = Protocol {
96 name: "+",
97 hash: Hash::new(0xe4ecf51fa0bf1076),
98 };
99
100 pub const ADD_ASSIGN: Protocol = Protocol {
102 name: "+=",
103 hash: Hash::new(0x42451ccb0a2071a9),
104 };
105
106 pub const SUB: Protocol = Protocol {
108 name: "-",
109 hash: Hash::new(0x6fa86a5f18d0bf71),
110 };
111
112 pub const SUB_ASSIGN: Protocol = Protocol {
114 name: "-=",
115 hash: Hash::new(0x5939bb56a1415284),
116 };
117
118 pub const MUL: Protocol = Protocol {
120 name: "*",
121 hash: Hash::new(0xb09e99dc94091d1c),
122 };
123
124 pub const MUL_ASSIGN: Protocol = Protocol {
126 name: "*=",
127 hash: Hash::new(0x29a54b727f980ebf),
128 };
129
130 pub const DIV: Protocol = Protocol {
132 name: "/",
133 hash: Hash::new(0xf26d6eea1afca6e8),
134 };
135
136 pub const DIV_ASSIGN: Protocol = Protocol {
138 name: "/=",
139 hash: Hash::new(0x4dd087a8281c04e6),
140 };
141
142 pub const REM: Protocol = Protocol {
144 name: "%",
145 hash: Hash::new(0x5c6293639c74e671),
146 };
147
148 pub const REM_ASSIGN: Protocol = Protocol {
150 name: "%=",
151 hash: Hash::new(0x3a8695980e77baf4),
152 };
153
154 pub const BIT_AND: Protocol = Protocol {
156 name: "&",
157 hash: Hash::new(0x0e11f20d940eebe8),
158 };
159
160 pub const BIT_AND_ASSIGN: Protocol = Protocol {
162 name: "&=",
163 hash: Hash::new(0x95cb1ba235dfb5ec),
164 };
165
166 pub const BIT_XOR: Protocol = Protocol {
168 name: "^",
169 hash: Hash::new(0xa3099c54e1de4cbf),
170 };
171
172 pub const BIT_XOR_ASSIGN: Protocol = Protocol {
174 name: "^=",
175 hash: Hash::new(0x01fa9706738f9867),
176 };
177
178 pub const BIT_OR: Protocol = Protocol {
180 name: "|",
181 hash: Hash::new(0x05010afceb4a03d0),
182 };
183
184 pub const BIT_OR_ASSIGN: Protocol = Protocol {
186 name: "|=",
187 hash: Hash::new(0x606d79ff1750a7ec),
188 };
189
190 pub const SHL: Protocol = Protocol {
192 name: "<<",
193 hash: Hash::new(0x6845f7d0cc9e002d),
194 };
195
196 pub const SHL_ASSIGN: Protocol = Protocol {
198 name: "<<=",
199 hash: Hash::new(0xdc4702d0307ba27b),
200 };
201
202 pub const SHR: Protocol = Protocol {
204 name: ">>",
205 hash: Hash::new(0x6b485e8e6e58fbc8),
206 };
207
208 pub const SHR_ASSIGN: Protocol = Protocol {
210 name: ">>=",
211 hash: Hash::new(0x61ff7c46ff00e74a),
212 };
213
214 pub const STRING_DISPLAY: Protocol = Protocol {
216 name: "string_display",
217 hash: Hash::new(0x811b62957ea9d9f9),
218 };
219
220 pub const STRING_DEBUG: Protocol = Protocol {
222 name: "string_debug",
223 hash: Hash::new(0x4064e3867aaa0717),
224 };
225
226 pub const INTO_ITER: Protocol = Protocol {
228 name: "into_iter",
229 hash: Hash::new(0x15a85c8d774b4065),
230 };
231
232 pub const NEXT: Protocol = Protocol {
234 name: "next",
235 hash: Hash::new(0xc3cde069de2ba320),
236 };
237
238 pub const INTO_FUTURE: Protocol = Protocol {
240 name: "into_future",
241 hash: Hash::new(0x596e6428deabfda2),
242 };
243
244 pub const INTO_TYPE_NAME: Protocol = Protocol {
246 name: "into_type_name",
247 hash: Hash::new(0xbffd08b816c24682),
248 };
249}