pub struct Skew { /* private fields */ }
Expand description
Represents value skews (see apply
for more information).
Implementations§
Source§impl Skew
impl Skew
Sourcepub fn apply(self, value: u64) -> impl Iterator<Item = u64>
pub fn apply(self, value: u64) -> impl Iterator<Item = u64>
Applies the skew to the given value.
Given some skew s
and value n
, this method returns an iterator that yields
n - s, n - s + 1, ..., n - 1, n, n + 1, ..., n + s - 1, n + s
§Note
In case of overflows, the iterator will skip the values that would cause them.
§Examples
Using zero to only accept the exact value:
use otp_std::Skew;
let skew = Skew::new(0);
let mut values = skew.apply(13);
assert_eq!(values.next(), Some(13));
assert_eq!(values.next(), None);
Using one:
use otp_std::Skew;
let skew = Skew::new(1);
let mut values = skew.apply(13);
assert_eq!(values.next(), Some(12));
assert_eq!(values.next(), Some(13));
assert_eq!(values.next(), Some(14));
assert_eq!(values.next(), None);
Overflow handling:
use otp_std::Skew;
let skew = Skew::new(1);
let value = u64::MAX;
let mut values = skew.apply(value);
assert_eq!(values.next(), Some(value - 1));
assert_eq!(values.next(), Some(value));
assert_eq!(values.next(), None);
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Skew
impl<'de> Deserialize<'de> for Skew
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Skew
impl Eq for Skew
impl StructuralPartialEq for Skew
Auto Trait Implementations§
impl Freeze for Skew
impl RefUnwindSafe for Skew
impl Send for Skew
impl Sync for Skew
impl Unpin for Skew
impl UnwindSafe for Skew
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more