pub struct Duration(/* private fields */);
Expand description
Represents a duration of time.
Implementations§
Source§impl Duration
impl Duration
Sourcepub const fn from_micros(val: u64) -> Self
pub const fn from_micros(val: u64) -> Self
Creates a duration which represents microseconds.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_micros(1000);
Sourcepub const fn from_millis(val: u64) -> Self
pub const fn from_millis(val: u64) -> Self
Creates a duration which represents milliseconds.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_millis(100);
Sourcepub const fn from_secs(val: u64) -> Self
pub const fn from_secs(val: u64) -> Self
Creates a duration which represents seconds.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_secs(1);
Sourcepub const fn from_minutes(val: u64) -> Self
pub const fn from_minutes(val: u64) -> Self
Creates a duration which represents minutes.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_minutes(1);
Sourcepub const fn from_hours(val: u64) -> Self
pub const fn from_hours(val: u64) -> Self
Creates a duration which represents hours.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_hours(1);
Sourcepub const fn as_micros(&self) -> u64
pub const fn as_micros(&self) -> u64
Convert the Duration
to an interger number of microseconds.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_micros(1000);
let micros = duration.as_micros();
Sourcepub const fn as_millis(&self) -> u64
pub const fn as_millis(&self) -> u64
Convert the Duration
to an interger number of milliseconds.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_millis(100);
let millis = duration.as_millis();
Sourcepub const fn as_secs(&self) -> u64
pub const fn as_secs(&self) -> u64
Convert the Duration
to an interger number of seconds.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_secs(1);
let secs = duration.as_secs();
Sourcepub const fn as_minutes(&self) -> u64
pub const fn as_minutes(&self) -> u64
Convert the Duration
to an interger number of minutes.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_minutes(1);
let minutes = duration.as_minutes();
Sourcepub const fn as_hours(&self) -> u64
pub const fn as_hours(&self) -> u64
Convert the Duration
to an interger number of hours.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_hours(1);
let hours = duration.as_hours();
Sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Add two durations while checking for overflow.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_secs(1);
let duration2 = Duration::from_secs(2);
if let Some(sum) = duration.checked_add(duration2) {
println!("Sum: {}", sum);
} else {
println!("Overflow occurred");
}
Sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Subtract two durations while checking for overflow.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_secs(3);
let duration2 = Duration::from_secs(1);
if let Some(diff) = duration.checked_sub(duration2) {
println!("Difference: {}", diff);
} else {
println!("Underflow occurred");
}
Sourcepub const fn saturating_add(self, rhs: Self) -> Self
pub const fn saturating_add(self, rhs: Self) -> Self
Add two durations, returning the maximum value if overflow occurred.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_secs(1);
let duration2 = Duration::from_secs(2);
let sum = duration.saturating_add(duration2);
Sourcepub const fn saturating_sub(self, rhs: Self) -> Self
pub const fn saturating_sub(self, rhs: Self) -> Self
Subtract two durations, returning the minimum value if the result would be negative.
§Example
use esp_hal::time::Duration;
let duration = Duration::from_secs(3);
let duration2 = Duration::from_secs(1);
let diff = duration.saturating_sub(duration2);
Trait Implementations§
Source§impl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moreSource§impl AddAssign for Duration
impl AddAssign for Duration
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl Ord for Duration
impl Ord for Duration
Source§impl PartialOrd for Duration
impl PartialOrd for Duration
Source§impl SubAssign<Duration> for Instant
impl SubAssign<Duration> for Instant
Source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moreSource§impl SubAssign for Duration
impl SubAssign for Duration
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read moreimpl Copy for Duration
impl Eq for Duration
impl StructuralPartialEq for Duration
Auto Trait Implementations§
impl Freeze for Duration
impl RefUnwindSafe for Duration
impl Send for Duration
impl Sync for Duration
impl Unpin for Duration
impl UnwindSafe for Duration
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit
)