/rust/registry/src/index.crates.io-6f17d22bba15001f/memchr-2.7.4/src/ext.rs
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /// A trait for adding some helper routines to pointers. | 
| 2 |  | pub(crate) trait Pointer { | 
| 3 |  |     /// Returns the distance, in units of `T`, between `self` and `origin`. | 
| 4 |  |     /// | 
| 5 |  |     /// # Safety | 
| 6 |  |     /// | 
| 7 |  |     /// Same as `ptr::offset_from` in addition to `self >= origin`. | 
| 8 |  |     unsafe fn distance(self, origin: Self) -> usize; | 
| 9 |  |  | 
| 10 |  |     /// Casts this pointer to `usize`. | 
| 11 |  |     /// | 
| 12 |  |     /// Callers should not convert the `usize` back to a pointer if at all | 
| 13 |  |     /// possible. (And if you believe it's necessary, open an issue to discuss | 
| 14 |  |     /// why. Otherwise, it has the potential to violate pointer provenance.) | 
| 15 |  |     /// The purpose of this function is just to be able to do arithmetic, i.e., | 
| 16 |  |     /// computing offsets or alignments. | 
| 17 |  |     fn as_usize(self) -> usize; | 
| 18 |  | } | 
| 19 |  |  | 
| 20 |  | impl<T> Pointer for *const T { | 
| 21 | 2.68M |     unsafe fn distance(self, origin: *const T) -> usize { | 
| 22 | 2.68M |         // TODO: Replace with `ptr::sub_ptr` once stabilized. | 
| 23 | 2.68M |         usize::try_from(self.offset_from(origin)).unwrap_unchecked() | 
| 24 | 2.68M |     } Unexecuted instantiation: <*const u8 as memchr::ext::Pointer>::distance<*const u8 as memchr::ext::Pointer>::distance| Line | Count | Source |  | 21 | 895k |     unsafe fn distance(self, origin: *const T) -> usize { |  | 22 | 895k |         // TODO: Replace with `ptr::sub_ptr` once stabilized. |  | 23 | 895k |         usize::try_from(self.offset_from(origin)).unwrap_unchecked() |  | 24 | 895k |     } | 
Unexecuted instantiation: <*const u8 as memchr::ext::Pointer>::distanceUnexecuted instantiation: <*const u8 as memchr::ext::Pointer>::distance<*const u8 as memchr::ext::Pointer>::distance| Line | Count | Source |  | 21 | 1.78M |     unsafe fn distance(self, origin: *const T) -> usize { |  | 22 | 1.78M |         // TODO: Replace with `ptr::sub_ptr` once stabilized. |  | 23 | 1.78M |         usize::try_from(self.offset_from(origin)).unwrap_unchecked() |  | 24 | 1.78M |     } | 
 | 
| 25 |  |  | 
| 26 | 0 |     fn as_usize(self) -> usize { | 
| 27 | 0 |         self as usize | 
| 28 | 0 |     } | 
| 29 |  | } | 
| 30 |  |  | 
| 31 |  | impl<T> Pointer for *mut T { | 
| 32 | 0 |     unsafe fn distance(self, origin: *mut T) -> usize { | 
| 33 | 0 |         (self as *const T).distance(origin as *const T) | 
| 34 | 0 |     } | 
| 35 |  |  | 
| 36 | 0 |     fn as_usize(self) -> usize { | 
| 37 | 0 |         (self as *const T).as_usize() | 
| 38 | 0 |     } | 
| 39 |  | } | 
| 40 |  |  | 
| 41 |  | /// A trait for adding some helper routines to raw bytes. | 
| 42 |  | #[cfg(test)] | 
| 43 |  | pub(crate) trait Byte { | 
| 44 |  |     /// Converts this byte to a `char` if it's ASCII. Otherwise panics. | 
| 45 |  |     fn to_char(self) -> char; | 
| 46 |  | } | 
| 47 |  |  | 
| 48 |  | #[cfg(test)] | 
| 49 |  | impl Byte for u8 { | 
| 50 |  |     fn to_char(self) -> char { | 
| 51 |  |         assert!(self.is_ascii()); | 
| 52 |  |         char::from(self) | 
| 53 |  |     } | 
| 54 |  | } |