mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-16 01:42:55 +00:00
Updates storage components to edition 2024. We like to stay on the latest edition if possible. There is no functional changes, however some code changes had to be done to accommodate the edition's breaking changes. The PR has two commits: * the first commit updates storage crates to edition 2024 and appeases `cargo clippy` by changing code. i have accidentially ran the formatter on some files that had other edits. * the second commit performs a `cargo fmt` I would recommend a closer review of the first commit and a less close review of the second one (as it just runs `cargo fmt`). part of https://github.com/neondatabase/neon/issues/10918
42 lines
1.0 KiB
Rust
42 lines
1.0 KiB
Rust
//! `u64`` and `usize`` aren't guaranteed to be identical in Rust, but life is much simpler if that's the case.
|
|
|
|
pub(crate) const _ASSERT_U64_EQ_USIZE: () = {
|
|
if std::mem::size_of::<usize>() != std::mem::size_of::<u64>() {
|
|
panic!(
|
|
"the traits defined in this module assume that usize and u64 can be converted to each other without loss of information"
|
|
);
|
|
}
|
|
};
|
|
|
|
pub(crate) trait U64IsUsize {
|
|
fn into_usize(self) -> usize;
|
|
}
|
|
|
|
impl U64IsUsize for u64 {
|
|
#[inline(always)]
|
|
fn into_usize(self) -> usize {
|
|
#[allow(clippy::let_unit_value)]
|
|
let _ = _ASSERT_U64_EQ_USIZE;
|
|
self as usize
|
|
}
|
|
}
|
|
|
|
pub(crate) trait UsizeIsU64 {
|
|
fn into_u64(self) -> u64;
|
|
}
|
|
|
|
impl UsizeIsU64 for usize {
|
|
#[inline(always)]
|
|
fn into_u64(self) -> u64 {
|
|
#[allow(clippy::let_unit_value)]
|
|
let _ = _ASSERT_U64_EQ_USIZE;
|
|
self as u64
|
|
}
|
|
}
|
|
|
|
pub const fn u64_to_usize(x: u64) -> usize {
|
|
#[allow(clippy::let_unit_value)]
|
|
let _ = _ASSERT_U64_EQ_USIZE;
|
|
x as usize
|
|
}
|