@@ -94,6 +94,11 @@ impl Level {
9494 }
9595 }
9696
97+ #[ must_use]
98+ fn as_repr ( self ) -> u16 {
99+ self as u16
100+ }
101+
97102 #[ must_use]
98103 const fn min_usize ( ) -> usize {
99104 Self :: most_severe ( ) as usize
@@ -310,11 +315,11 @@ impl From<log::LevelFilter> for LevelFilter {
310315
311316// Atomic
312317
313- #[ repr( align( 4 ) ) ]
314- #[ derive( Copy , Clone , Eq , PartialEq , Hash , Debug ) ]
318+ #[ repr( C , align( 4 ) ) ]
319+ #[ derive( Copy , Clone , Eq , PartialEq , Hash , Debug , bytemuck :: NoUninit ) ]
315320struct AtomicLevelFilterInner {
316321 discriminant : u16 , // Keep the type in sync with the repr of `LevelFilter`
317- level : Level , // Keep the type in sync with the variants of `LevelFilter`
322+ level : u16 , // Keep the type in sync with the variants of `LevelFilter`
318323}
319324
320325impl AtomicLevelFilterInner {
@@ -325,15 +330,15 @@ impl From<LevelFilter> for AtomicLevelFilterInner {
325330 fn from ( value : LevelFilter ) -> Self {
326331 Self {
327332 discriminant : value. discriminant ( ) ,
328- level : value. level ( ) . unwrap_or ( Self :: UNDEFINED_FALLBACK ) ,
333+ level : value. level ( ) . unwrap_or ( Self :: UNDEFINED_FALLBACK ) . as_repr ( ) ,
329334 }
330335 }
331336}
332337
333338impl From < AtomicLevelFilterInner > for LevelFilter {
334339 fn from ( inner : AtomicLevelFilterInner ) -> Self {
335340 // SAFETY:
336- // TODO
341+ // `AtomicLevelFilterInner` and `LevelFilter` have the same layout.
337342 unsafe { mem:: transmute ( inner) }
338343 }
339344}
0 commit comments