pub struct Timeout { /* private fields */ }
Expand description

Timeout argument.

This is used by:

Each timeout has 3 bytes, with a resolution of 15.625µs per bit, giving a range of 0s to 262.143984375s.

Implementations§

source§

impl Timeout

source

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));
source

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);
source

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));
source

pub const RESOLUTION_NANOS: u16 = 15_625u16

Timeout resolution in nanoseconds, 15.625µs.

source

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
);
source

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))
);
source

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
);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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]);
source

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 Clone for Timeout

source§

fn clone(&self) -> Timeout

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Timeout

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Timeout> for [u8; 3]

source§

fn from(to: Timeout) -> Self

Converts to this type from the input type.
source§

impl From<Timeout> for Duration

source§

fn from(to: Timeout) -> Self

Converts to this type from the input type.
source§

impl Ord for Timeout

source§

fn cmp(&self, other: &Timeout) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Timeout

source§

fn eq(&self, other: &Timeout) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Timeout

source§

fn partial_cmp(&self, other: &Timeout) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for Timeout

source§

impl Eq for Timeout

source§

impl StructuralEq for Timeout

source§

impl StructuralPartialEq for Timeout

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.