1
1
use core:: fmt:: { Debug , Formatter } ;
2
+ use core:: hash:: { Hash , Hasher } ;
2
3
use core:: marker:: PhantomData ;
3
4
4
5
/// Magic number that a multiboot2-compliant boot loader will store in `eax` register
@@ -14,7 +15,7 @@ pub const MULTIBOOT2_BOOTLOADER_MAGIC: u32 = 0x36d76289;
14
15
/// of the the `typ` property. The names and values are taken from the example C code
15
16
/// at the bottom of the Multiboot2 specification.
16
17
#[ repr( u32 ) ]
17
- #[ derive( Copy , Clone , Debug ) ]
18
+ #[ derive( Copy , Clone , Debug , Eq ) ]
18
19
pub enum TagType {
19
20
/// Marks the end of the tags.
20
21
End = 0 ,
@@ -115,6 +116,13 @@ impl PartialEq<TagType> for TagType {
115
116
}
116
117
}
117
118
119
+ // impl required because this type is used in a hashmap in `multiboot2-header`
120
+ impl Hash for TagType {
121
+ fn hash < H : Hasher > ( & self , state : & mut H ) {
122
+ state. write_u32 ( * self as u32 ) ;
123
+ }
124
+ }
125
+
118
126
/// All tags that could passed via the Multiboot2 information structure to a payload/program/kernel.
119
127
/// Better not confuse this with the Multiboot2 header tags. They are something different.
120
128
#[ derive( Clone , Copy ) ]
@@ -171,3 +179,20 @@ impl<'a> Iterator for TagIter<'a> {
171
179
}
172
180
}
173
181
}
182
+
183
+ #[ cfg( test) ]
184
+ mod tests {
185
+ use super :: * ;
186
+
187
+ #[ test]
188
+ fn test_hash ( ) {
189
+ let mut hashset = std:: collections:: HashSet :: new ( ) ;
190
+ hashset. insert ( TagType :: Cmdline ) ;
191
+ hashset. insert ( TagType :: ElfSections ) ;
192
+ hashset. insert ( TagType :: BootLoaderName ) ;
193
+ hashset. insert ( TagType :: LoadBaseAddr ) ;
194
+ hashset. insert ( TagType :: LoadBaseAddr ) ;
195
+ assert_eq ! ( hashset. len( ) , 4 ) ;
196
+ println ! ( "{:#?}" , hashset) ;
197
+ }
198
+ }
0 commit comments