Struct stm32wlxx_hal::subghz::Timeout
source · pub struct Timeout { /* private fields */ }
Expand description
Implementations§
source§impl Timeout
impl Timeout
sourcepub const DISABLED: Timeout = _
pub const DISABLED: Timeout = _
Disable the timeout (0s timeout).
Example
use core::time::Duration;
use stm32wlxx_hal::subghz::Timeout;
const TIMEOUT: Timeout = Timeout::DISABLED;
assert_eq!(TIMEOUT.as_duration(), Duration::from_secs(0));
sourcepub const MIN: Timeout = _
pub const MIN: Timeout = _
Minimum timeout, 15.625µs.
Example
use core::time::Duration;
use stm32wlxx_hal::subghz::Timeout;
const TIMEOUT: Timeout = Timeout::MIN;
assert_eq!(TIMEOUT.into_bits(), 1);
sourcepub const MAX: Timeout = _
pub const MAX: Timeout = _
Maximum timeout, 262.143984375s.
Example
use core::time::Duration;
use stm32wlxx_hal::subghz::Timeout;
const TIMEOUT: Timeout = Timeout::MAX;
assert_eq!(TIMEOUT.as_duration(), Duration::from_nanos(262_143_984_375));
sourcepub const RESOLUTION_NANOS: u16 = 15_625u16
pub const RESOLUTION_NANOS: u16 = 15_625u16
Timeout resolution in nanoseconds, 15.625µs.
sourcepub const RESOLUTION: Duration = _
pub const RESOLUTION: Duration = _
Timeout resolution, 15.625µs.
Example
use stm32wlxx_hal::subghz::Timeout;
assert_eq!(
Timeout::RESOLUTION.as_nanos(),
Timeout::RESOLUTION_NANOS as u128
);
sourcepub const fn from_duration(
duration: Duration
) -> Result<Timeout, ValueError<u128>>
pub const fn from_duration( duration: Duration ) -> Result<Timeout, ValueError<u128>>
Create a new timeout from a Duration
.
This will return the nearest timeout value possible, or a
ValueError
if the value is out of bounds.
Use from_millis_sat
for runtime timeout
construction.
This is not that useful right now, it is simply future proofing for a
time when Result::unwrap
is available for const fn
.
Example
Value within bounds:
use core::time::Duration;
use stm32wlxx_hal::subghz::{Timeout, ValueError};
const MIN: Duration = Timeout::RESOLUTION;
assert_eq!(Timeout::from_duration(MIN).unwrap(), Timeout::MIN);
Value too low:
use core::time::Duration;
use stm32wlxx_hal::subghz::{Timeout, ValueError};
const LOWER_LIMIT_NANOS: u128 = 7813;
const TOO_LOW_NANOS: u128 = LOWER_LIMIT_NANOS - 1;
const TOO_LOW_DURATION: Duration = Duration::from_nanos(TOO_LOW_NANOS as u64);
assert_eq!(
Timeout::from_duration(TOO_LOW_DURATION),
Err(ValueError::too_low(TOO_LOW_NANOS, LOWER_LIMIT_NANOS))
);
Value too high:
use core::time::Duration;
use stm32wlxx_hal::subghz::{Timeout, ValueError};
const UPPER_LIMIT_NANOS: u128 = Timeout::MAX.as_nanos() as u128 + 7812;
const TOO_HIGH_NANOS: u128 = UPPER_LIMIT_NANOS + 1;
const TOO_HIGH_DURATION: Duration = Duration::from_nanos(TOO_HIGH_NANOS as u64);
assert_eq!(
Timeout::from_duration(TOO_HIGH_DURATION),
Err(ValueError::too_high(TOO_HIGH_NANOS, UPPER_LIMIT_NANOS))
);
sourcepub const fn from_duration_sat(duration: Duration) -> Timeout
pub const fn from_duration_sat(duration: Duration) -> Timeout
Create a new timeout from a Duration
.
This will return the nearest timeout value possible, saturating at the limits.
This is an expensive function to call outside of const
contexts.
Use from_millis_sat
for runtime timeout
construction.
Example
use core::time::Duration;
use stm32wlxx_hal::subghz::Timeout;
const DURATION_MAX_NS: u64 = 262_143_984_376;
assert_eq!(
Timeout::from_duration_sat(Duration::from_millis(0)),
Timeout::MIN
);
assert_eq!(
Timeout::from_duration_sat(Duration::from_nanos(DURATION_MAX_NS)),
Timeout::MAX
);
assert_eq!(
Timeout::from_duration_sat(Timeout::RESOLUTION).into_bits(),
1
);
sourcepub const fn from_millis_sat(millis: u32) -> Timeout
pub const fn from_millis_sat(millis: u32) -> Timeout
Create a new timeout from a milliseconds value.
This will round towards zero and saturate at the limits.
This is the preferred method to call when you need to generate a timeout value at runtime.
Example
use stm32wlxx_hal::subghz::Timeout;
assert_eq!(Timeout::from_millis_sat(0), Timeout::MIN);
assert_eq!(Timeout::from_millis_sat(262_144), Timeout::MAX);
assert_eq!(Timeout::from_millis_sat(1).into_bits(), 64);
sourcepub const fn from_raw(bits: u32) -> Timeout
pub const fn from_raw(bits: u32) -> Timeout
Create a timeout from raw bits, where each bit has the resolution of
Timeout::RESOLUTION
.
Note: Only the first 24 bits of the u32
are used, the bits
argument will be masked.
Example
use stm32wlxx_hal::subghz::Timeout;
assert_eq!(Timeout::from_raw(u32::MAX), Timeout::MAX);
assert_eq!(Timeout::from_raw(0x00_FF_FF_FF), Timeout::MAX);
assert_eq!(Timeout::from_raw(1).as_duration(), Timeout::RESOLUTION);
assert_eq!(Timeout::from_raw(0), Timeout::DISABLED);
sourcepub const fn as_nanos(&self) -> u64
pub const fn as_nanos(&self) -> u64
Get the timeout as nanoseconds.
Example
use stm32wlxx_hal::subghz::Timeout;
assert_eq!(Timeout::MAX.as_nanos(), 262_143_984_375);
assert_eq!(Timeout::DISABLED.as_nanos(), 0);
assert_eq!(Timeout::from_raw(1).as_nanos(), 15_625);
assert_eq!(Timeout::from_raw(64_000).as_nanos(), 1_000_000_000);
sourcepub const fn as_micros(&self) -> u32
pub const fn as_micros(&self) -> u32
Get the timeout as microseconds, rounding towards zero.
Example
use stm32wlxx_hal::subghz::Timeout;
assert_eq!(Timeout::MAX.as_micros(), 262_143_984);
assert_eq!(Timeout::DISABLED.as_micros(), 0);
assert_eq!(Timeout::from_raw(1).as_micros(), 15);
assert_eq!(Timeout::from_raw(64_000).as_micros(), 1_000_000);
sourcepub const fn as_millis(&self) -> u32
pub const fn as_millis(&self) -> u32
Get the timeout as milliseconds, rounding towards zero.
Example
use stm32wlxx_hal::subghz::Timeout;
assert_eq!(Timeout::MAX.as_millis(), 262_143);
assert_eq!(Timeout::DISABLED.as_millis(), 0);
assert_eq!(Timeout::from_raw(1).as_millis(), 0);
assert_eq!(Timeout::from_raw(64_000).as_millis(), 1_000);
sourcepub const fn as_secs(&self) -> u16
pub const fn as_secs(&self) -> u16
Get the timeout as seconds, rounding towards zero.
Example
use stm32wlxx_hal::subghz::Timeout;
assert_eq!(Timeout::MAX.as_secs(), 262);
assert_eq!(Timeout::DISABLED.as_secs(), 0);
assert_eq!(Timeout::from_raw(1).as_secs(), 0);
assert_eq!(Timeout::from_raw(64_000).as_secs(), 1);
sourcepub const fn as_duration(&self) -> Duration
pub const fn as_duration(&self) -> Duration
Get the timeout as a Duration
.
Example
use core::time::Duration;
use stm32wlxx_hal::subghz::Timeout;
assert_eq!(
Timeout::MAX.as_duration(),
Duration::from_nanos(262_143_984_375)
);
assert_eq!(Timeout::DISABLED.as_duration(), Duration::from_nanos(0));
assert_eq!(Timeout::from_raw(1).as_duration(), Timeout::RESOLUTION);
sourcepub const fn into_bits(self) -> u32
pub const fn into_bits(self) -> u32
Get the bit value for the timeout.
Example
use stm32wlxx_hal::subghz::Timeout;
assert_eq!(Timeout::from_raw(u32::MAX).into_bits(), 0x00FF_FFFF);
assert_eq!(Timeout::from_raw(1).into_bits(), 1);
sourcepub const fn as_bytes(self) -> [u8; 3]
pub const fn as_bytes(self) -> [u8; 3]
Get the byte value for the timeout.
Example
use stm32wlxx_hal::subghz::Timeout;
assert_eq!(Timeout::from_raw(u32::MAX).as_bytes(), [0xFF, 0xFF, 0xFF]);
assert_eq!(Timeout::from_raw(1).as_bytes(), [0, 0, 1]);
sourcepub const fn saturating_add(self, rhs: Self) -> Self
pub const fn saturating_add(self, rhs: Self) -> Self
Saturating timeout addition. Computes self + rhs
, saturating at the
numeric bounds instead of overflowing.
Example
use stm32wlxx_hal::subghz::Timeout;
assert_eq!(
Timeout::from_raw(0xFF_FF_F0).saturating_add(Timeout::from_raw(0xFF)),
Timeout::from_raw(0xFF_FF_FF)
);
assert_eq!(
Timeout::from_raw(100).saturating_add(Timeout::from_raw(23)),
Timeout::from_raw(123)
);
Trait Implementations§
source§impl Ord for Timeout
impl Ord for Timeout
source§impl PartialEq for Timeout
impl PartialEq for Timeout
source§impl PartialOrd for Timeout
impl PartialOrd for Timeout
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more