LCOV - code coverage report
Current view: top level - pageserver/src - assert_u64_eq_usize.rs (source / functions) Coverage Total Hit
Test: b4ae4c4857f9ef3e144e982a35ee23bc84c71983.info Lines: 100.0 % 15 15
Test Date: 2024-10-22 22:13:45 Functions: 100.0 % 3 3

            Line data    Source code
       1              : //! `u64`` and `usize`` aren't guaranteed to be identical in Rust, but life is much simpler if that's the case.
       2              : 
       3              : pub(crate) const _ASSERT_U64_EQ_USIZE: () = {
       4              :     if std::mem::size_of::<usize>() != std::mem::size_of::<u64>() {
       5              :         panic!("the traits defined in this module assume that usize and u64 can be converted to each other without loss of information");
       6              :     }
       7              : };
       8              : 
       9              : pub(crate) trait U64IsUsize {
      10              :     fn into_usize(self) -> usize;
      11              : }
      12              : 
      13              : impl U64IsUsize for u64 {
      14              :     #[inline(always)]
      15     18347062 :     fn into_usize(self) -> usize {
      16     18347062 :         #[allow(clippy::let_unit_value)]
      17     18347062 :         let _ = _ASSERT_U64_EQ_USIZE;
      18     18347062 :         self as usize
      19     18347062 :     }
      20              : }
      21              : 
      22              : pub(crate) trait UsizeIsU64 {
      23              :     fn into_u64(self) -> u64;
      24              : }
      25              : 
      26              : impl UsizeIsU64 for usize {
      27              :     #[inline(always)]
      28     23849302 :     fn into_u64(self) -> u64 {
      29     23849302 :         #[allow(clippy::let_unit_value)]
      30     23849302 :         let _ = _ASSERT_U64_EQ_USIZE;
      31     23849302 :         self as u64
      32     23849302 :     }
      33              : }
      34              : 
      35          204 : pub const fn u64_to_usize(x: u64) -> usize {
      36          204 :     #[allow(clippy::let_unit_value)]
      37          204 :     let _ = _ASSERT_U64_EQ_USIZE;
      38          204 :     x as usize
      39          204 : }
        

Generated by: LCOV version 2.1-beta