diff options
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 } } |