mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-12-25 13:09:41 +00:00
Merge branch 'main' into rpc-handler
This commit is contained in:
commit
57677a5e90
2 changed files with 11 additions and 9 deletions
|
@ -4,14 +4,16 @@
|
||||||
//!
|
//!
|
||||||
//! `#[no_std]` compatible.
|
//! `#[no_std]` compatible.
|
||||||
|
|
||||||
|
#![allow(clippy::cast_possible_truncation)]
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
//============================ SAFETY: DO NOT REMOVE ===========================//
|
//============================ SAFETY: DO NOT REMOVE ===========================//
|
||||||
// //
|
// //
|
||||||
// //
|
// //
|
||||||
// Only allow building 64-bit targets. //
|
// Only allow building 64-bit targets. //
|
||||||
// This allows us to assume 64-bit invariants in this file. //
|
// This allows us to assume 64-bit invariants in this file. //
|
||||||
#[cfg(not(target_pointer_width = "64"))]
|
#[cfg(not(target_pointer_width = "64"))]
|
||||||
compile_error!("Cuprate is only compatible with 64-bit CPUs");
|
compile_error!("Cuprate is only compatible with 64-bit CPUs");
|
||||||
// //
|
// //
|
||||||
// //
|
// //
|
||||||
//============================ SAFETY: DO NOT REMOVE ===========================//
|
//============================ SAFETY: DO NOT REMOVE ===========================//
|
||||||
|
@ -60,8 +62,8 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn max_unsigned() {
|
fn max_unsigned() {
|
||||||
assert_eq!(u32_to_usize(u32::MAX), u32::MAX as usize);
|
assert_eq!(u32_to_usize(u32::MAX), usize::try_from(u32::MAX).unwrap());
|
||||||
assert_eq!(usize_to_u64(u32_to_usize(u32::MAX)), u32::MAX as u64);
|
assert_eq!(usize_to_u64(u32_to_usize(u32::MAX)), u64::from(u32::MAX));
|
||||||
|
|
||||||
assert_eq!(u64_to_usize(u64::MAX), usize::MAX);
|
assert_eq!(u64_to_usize(u64::MAX), usize::MAX);
|
||||||
assert_eq!(usize_to_u64(u64_to_usize(u64::MAX)), u64::MAX);
|
assert_eq!(usize_to_u64(u64_to_usize(u64::MAX)), u64::MAX);
|
||||||
|
@ -72,8 +74,8 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn max_signed() {
|
fn max_signed() {
|
||||||
assert_eq!(i32_to_isize(i32::MAX), i32::MAX as isize);
|
assert_eq!(i32_to_isize(i32::MAX), isize::try_from(i32::MAX).unwrap());
|
||||||
assert_eq!(isize_to_i64(i32_to_isize(i32::MAX)), i32::MAX as i64);
|
assert_eq!(isize_to_i64(i32_to_isize(i32::MAX)), i64::from(i32::MAX));
|
||||||
|
|
||||||
assert_eq!(i64_to_isize(i64::MAX), isize::MAX);
|
assert_eq!(i64_to_isize(i64::MAX), isize::MAX);
|
||||||
assert_eq!(isize_to_i64(i64_to_isize(i64::MAX)), i64::MAX);
|
assert_eq!(isize_to_i64(i64_to_isize(i64::MAX)), i64::MAX);
|
||||||
|
|
|
@ -76,7 +76,7 @@ pub const fn combine_low_high_bits_to_u128(low_bits: u64, high_bits: u64) -> u12
|
||||||
/// assert_eq!(u64_to_timelock(499_999_999), Timelock::Block(499_999_999));
|
/// assert_eq!(u64_to_timelock(499_999_999), Timelock::Block(499_999_999));
|
||||||
/// assert_eq!(u64_to_timelock(500_000_000), Timelock::Time(500_000_000));
|
/// assert_eq!(u64_to_timelock(500_000_000), Timelock::Time(500_000_000));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn u64_to_timelock(u: u64) -> Timelock {
|
pub const fn u64_to_timelock(u: u64) -> Timelock {
|
||||||
if u == 0 {
|
if u == 0 {
|
||||||
Timelock::None
|
Timelock::None
|
||||||
} else if u < 500_000_000 {
|
} else if u < 500_000_000 {
|
||||||
|
@ -97,7 +97,7 @@ pub fn u64_to_timelock(u: u64) -> Timelock {
|
||||||
/// assert_eq!(timelock_to_u64(Timelock::Block(499_999_999)), 499_999_999);
|
/// assert_eq!(timelock_to_u64(Timelock::Block(499_999_999)), 499_999_999);
|
||||||
/// assert_eq!(timelock_to_u64(Timelock::Time(500_000_000)), 500_000_000);
|
/// assert_eq!(timelock_to_u64(Timelock::Time(500_000_000)), 500_000_000);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn timelock_to_u64(timelock: Timelock) -> u64 {
|
pub const fn timelock_to_u64(timelock: Timelock) -> u64 {
|
||||||
match timelock {
|
match timelock {
|
||||||
Timelock::None => 0,
|
Timelock::None => 0,
|
||||||
Timelock::Block(u) => usize_to_u64(u),
|
Timelock::Block(u) => usize_to_u64(u),
|
||||||
|
|
Loading…
Reference in a new issue