diff --git a/src/index.rs b/src/index.rs index 98f88e4c..061bde46 100644 --- a/src/index.rs +++ b/src/index.rs @@ -106,7 +106,6 @@ where R: BitRegister /// Removes the index wrapper, leaving the internal counter. #[inline] - #[cfg(not(tarpaulin_include))] pub fn into_inner(self) -> u8 { self.idx } @@ -593,6 +592,14 @@ where R: BitRegister } } +impl From> for BitEnd { + fn from(idx: BitIdx) -> Self { + // SAFETY: Maximum allowed value of BitIdx is always smaller + // than maximum allowed value of BitEnd. + unsafe { Self::new_unchecked(idx.into_inner()) } + } +} + #[repr(transparent)] #[doc = include_str!("../doc/index/BitPos.md")] // #[rustc_layout_scalar_valid_range_end(R::BITS)] @@ -1083,6 +1090,12 @@ mod tests { assert!(BitEnd::::new(n).is_some()); } assert!(BitEnd::::new(bits_of::() as u8 + 1).is_none()); + + for n in 0 .. bits_of::() as u8 { + let idx = BitIdx::::new(n).unwrap(); + let end = BitEnd::::new(n).unwrap(); + assert_eq!(end, BitEnd::from(idx)); + } } #[test]