diff options
author | superwhiskers <[email protected]> | 2025-08-27 14:41:19 -0500 |
---|---|---|
committer | superwhiskers <[email protected]> | 2025-09-15 10:55:10 -0500 |
commit | 83751efd734999fc11316a66317250ca53e76726 (patch) | |
tree | f5917c5c0bc8fd5883f7893eb5d4b9853585aea7 /crates/core/src/hive/skipfield.rs | |
parent | 386279ce28a54002fa91f436d5b60815c537e910 (diff) | |
download | azimuth-83751efd734999fc11316a66317250ca53e76726.tar.gz azimuth-83751efd734999fc11316a66317250ca53e76726.tar.bz2 azimuth-83751efd734999fc11316a66317250ca53e76726.zip |
initial expression implementation
Change-Id: I6a6a69640c133bce112891bba09033b08e7c0dec
Diffstat (limited to 'crates/core/src/hive/skipfield.rs')
-rw-r--r-- | crates/core/src/hive/skipfield.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/crates/core/src/hive/skipfield.rs b/crates/core/src/hive/skipfield.rs index 0fb2ab4..16a3dcb 100644 --- a/crates/core/src/hive/skipfield.rs +++ b/crates/core/src/hive/skipfield.rs @@ -4,7 +4,10 @@ //! types may be used by implementing this trait on them; the trait is not //! sealed. -use core::ops::{Add, AddAssign, Sub, SubAssign}; +use core::{ + cmp, + ops::{Add, AddAssign, Sub, SubAssign}, +}; /// Trait describing integral types in a generic way suitable for use as the /// element type of a skipfield. @@ -21,9 +24,13 @@ pub trait SkipfieldType: const ONE: Self; /// Conversion method from `usize` using `as` or an equivalent + /// + /// Caps the value of the input by the maximum of `Self`. fn from_usize(u: usize) -> Self; /// Conversion method from `isize` using `as` or an equivalent + /// + /// Caps the value of the input by the maximum of `Self`. fn from_isize(i: isize) -> Self; } @@ -34,12 +41,12 @@ impl SkipfieldType for u16 { #[inline(always)] fn from_usize(u: usize) -> Self { - u as u16 + cmp::min(u, Self::MAXIMUM as usize) as u16 } #[inline(always)] fn from_isize(i: isize) -> Self { - i as u16 + cmp::min(i, Self::MAXIMUM as isize) as u16 } } @@ -50,11 +57,11 @@ impl SkipfieldType for u8 { #[inline(always)] fn from_usize(u: usize) -> Self { - u as u8 + cmp::min(u, Self::MAXIMUM as usize) as u8 } #[inline(always)] fn from_isize(i: isize) -> Self { - i as u8 + cmp::min(i, Self::MAXIMUM as isize) as u8 } } |