11use core:: fmt:: { Debug , Formatter } ;
2+ use core:: hash:: { Hash , Hasher } ;
23use core:: marker:: PhantomData ;
34
45/// Magic number that a multiboot2-compliant boot loader will store in `eax` register
@@ -14,7 +15,7 @@ pub const MULTIBOOT2_BOOTLOADER_MAGIC: u32 = 0x36d76289;
1415/// of the the `typ` property. The names and values are taken from the example C code
1516/// at the bottom of the Multiboot2 specification.
1617#[ repr( u32 ) ]
17- #[ derive( Copy , Clone , Debug ) ]
18+ #[ derive( Copy , Clone , Debug , Eq ) ]
1819pub enum TagType {
1920 /// Marks the end of the tags.
2021 End = 0 ,
@@ -115,6 +116,13 @@ impl PartialEq<TagType> for TagType {
115116 }
116117}
117118
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+
118126/// All tags that could passed via the Multiboot2 information structure to a payload/program/kernel.
119127/// Better not confuse this with the Multiboot2 header tags. They are something different.
120128#[ derive( Clone , Copy ) ]
@@ -171,3 +179,20 @@ impl<'a> Iterator for TagIter<'a> {
171179 }
172180 }
173181}
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