pub struct AvrDuration { /* private fields */ }
Expand description
Like std::time::Duration
, but in AVR cycles; somewhat approximate¹.
Implementations§
Source§impl AvrDuration
impl AvrDuration
Sourcepub const fn new(clock_frequency: u32, cycles: u64) -> Self
pub const fn new(clock_frequency: u32, cycles: u64) -> Self
Creates a new duration for given clock frequency and number of cycles:
AvrDuration::new(
16_000_000, /* 16 MHz */
8_000_000, /* 8 million clock cycles (=500ms here) */
);
If you’re using AvrTester, you might find AvrDurationExt
more
convenient than this constructor.
Sourcepub const fn add_cycles(self, n: u64) -> Self
pub const fn add_cycles(self, n: u64) -> Self
Returns a new duration with increased number of cycles.
§Examples
let tt = AvrDuration::new(16_000_000, 8_000_000);
assert_eq!(500, tt.as_millis());
assert_eq!(750, tt.add_cycles(4_000_000).as_millis());
Sourcepub const fn add_micros(self, n: u64) -> Self
pub const fn add_micros(self, n: u64) -> Self
Returns a new duration with increased number of microseconds.
§Examples
let tt = AvrDuration::new(16_000_000, 8_000_000);
assert_eq!(500, tt.as_millis());
assert_eq!(501, tt.add_micros(1_000).as_millis());
Sourcepub const fn add_millis(self, millis: u64) -> Self
pub const fn add_millis(self, millis: u64) -> Self
Returns a new duration with increased number of milliseconds.
§Examples
let tt = AvrDuration::new(16_000_000, 8_000_000);
assert_eq!(500, tt.as_millis());
assert_eq!(515, tt.add_millis(15).as_millis());
Sourcepub const fn add_secs(self, secs: u64) -> Self
pub const fn add_secs(self, secs: u64) -> Self
Returns a new duration with increased number of seconds.
§Examples
let tt = AvrDuration::new(16_000_000, 8_000_000);
assert_eq!(500, tt.as_millis());
assert_eq!(2500, tt.add_secs(2).as_millis());
Sourcepub const fn with_cycles(self, n: u64) -> Self
pub const fn with_cycles(self, n: u64) -> Self
Returns a new duration with specified number of cycles.
§Examples
let tt = AvrDuration::new(16_000_000, 8_000_000);
assert_eq!(250, tt.with_cycles(4_000_000).as_millis());
Sourcepub const fn with_micros(self, n: u64) -> Self
pub const fn with_micros(self, n: u64) -> Self
Returns a new duration with specified number of microseconds.
§Examples
let tt = AvrDuration::new(16_000_000, 8_000_000);
assert_eq!(1, tt.with_micros(1_000).as_millis());
Sourcepub const fn with_millis(self, n: u64) -> Self
pub const fn with_millis(self, n: u64) -> Self
Returns a new duration with specified number of milliseconds.
§Examples
let tt = AvrDuration::new(16_000_000, 8_000_000);
assert_eq!(15, tt.with_millis(15).as_millis());
Sourcepub const fn with_secs(self, n: u64) -> Self
pub const fn with_secs(self, n: u64) -> Self
Returns a new duration with specified number of seconds.
§Examples
let tt = AvrDuration::new(16_000_000, 8_000_000);
assert_eq!(2000, tt.with_secs(2).as_millis());
Sourcepub const fn clock_frequency(self) -> u32
pub const fn clock_frequency(self) -> u32
Returns the clock frequency associated with this duration (e.g. 16 MHz).
§Examples
let tt = AvrDuration::new(16_000_000, 8_000_000);
assert_eq!(16_000_000, tt.clock_frequency());
Sourcepub const fn as_cycles(self) -> u64
pub const fn as_cycles(self) -> u64
Returns the number of cycles contained by this duration.
§Examples
let tt = AvrDuration::new(16_000_000, 8_000_000);
assert_eq!(8_000_000, tt.as_cycles());
let tt = AvrDuration::new(16_000_000, 0).add_secs(3);
assert_eq!(48_000_000, tt.as_cycles());
Sourcepub fn as_micros(self) -> u64
pub fn as_micros(self) -> u64
Returns the number of microseconds contained by this duration.
§Examples
let tt = AvrDuration::new(16_000_000, 40);
assert_eq!(3, tt.as_micros());
Sourcepub fn as_micros_f64(self) -> f64
pub fn as_micros_f64(self) -> f64
Returns the number of microseconds contained by this duration as f64
.
§Examples
let tt = AvrDuration::new(16_000_000, 40);
assert_eq!(2.5, tt.as_micros_f64());
Sourcepub fn as_millis(self) -> u64
pub fn as_millis(self) -> u64
Returns the number of milliseconds contained by this duration.
§Examples
let tt = AvrDuration::new(16_000_000, 40_000);
assert_eq!(3, tt.as_millis());
Sourcepub fn as_millis_f64(self) -> f64
pub fn as_millis_f64(self) -> f64
Returns the number of milliseconds contained by this duration as f64
.
§Examples
let tt = AvrDuration::new(16_000_000, 40_000);
assert_eq!(2.5, tt.as_millis_f64());
Sourcepub fn as_secs(self) -> u64
pub fn as_secs(self) -> u64
Returns the number of seconds contained by this duration.
§Examples
let tt = AvrDuration::new(16_000_000, 40_000_000);
assert_eq!(3, tt.as_secs());
Sourcepub fn as_secs_f64(self) -> f64
pub fn as_secs_f64(self) -> f64
Returns the number of seconds contained by this duration as f64
.
§Examples
let tt = AvrDuration::new(16_000_000, 40_000_000);
assert_eq!(2.5, tt.as_secs_f64());
Trait Implementations§
Source§impl Add for AvrDuration
§Examples
let a = AvrDuration::new(16_000_000, 1_000);
let b = AvrDuration::new(16_000_000, 2_000);
assert_eq!(
AvrDuration::new(16_000_000, 3_000),
a + b,
);
impl Add for AvrDuration
§Examples
let a = AvrDuration::new(16_000_000, 1_000);
let b = AvrDuration::new(16_000_000, 2_000);
assert_eq!(
AvrDuration::new(16_000_000, 3_000),
a + b,
);
Source§impl AddAssign for AvrDuration
§Examples
let mut a = AvrDuration::new(16_000_000, 1_000);
a += AvrDuration::new(16_000_000, 2_000);
assert_eq!(AvrDuration::new(16_000_000, 3_000), a);
impl AddAssign for AvrDuration
§Examples
let mut a = AvrDuration::new(16_000_000, 1_000);
a += AvrDuration::new(16_000_000, 2_000);
assert_eq!(AvrDuration::new(16_000_000, 3_000), a);
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl Clone for AvrDuration
impl Clone for AvrDuration
Source§fn clone(&self) -> AvrDuration
fn clone(&self) -> AvrDuration
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for AvrDuration
impl Debug for AvrDuration
Source§impl Display for AvrDuration
§Examples
let tt = AvrDuration::new(16_000_000, 0).add_millis(123);
assert_eq!("123000 µs", tt.to_string());
impl Display for AvrDuration
§Examples
let tt = AvrDuration::new(16_000_000, 0).add_millis(123);
assert_eq!("123000 µs", tt.to_string());
Source§impl Hash for AvrDuration
impl Hash for AvrDuration
Source§impl Ord for AvrDuration
impl Ord for AvrDuration
Source§fn cmp(&self, other: &AvrDuration) -> Ordering
fn cmp(&self, other: &AvrDuration) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for AvrDuration
impl PartialEq for AvrDuration
Source§impl PartialOrd for AvrDuration
impl PartialOrd for AvrDuration
Source§impl Sub for AvrDuration
§Examples
let a = AvrDuration::new(16_000_000, 3_000);
let b = AvrDuration::new(16_000_000, 2_000);
assert_eq!(
AvrDuration::new(16_000_000, 1_000),
a - b,
);
let a = AvrDuration::new(16_000_000, 3_000);
let b = AvrDuration::new(16_000_000, 4_000);
assert_eq!(
AvrDuration::new(16_000_000, 0),
a - b,
);
impl Sub for AvrDuration
§Examples
let a = AvrDuration::new(16_000_000, 3_000);
let b = AvrDuration::new(16_000_000, 2_000);
assert_eq!(
AvrDuration::new(16_000_000, 1_000),
a - b,
);
let a = AvrDuration::new(16_000_000, 3_000);
let b = AvrDuration::new(16_000_000, 4_000);
assert_eq!(
AvrDuration::new(16_000_000, 0),
a - b,
);
Source§impl SubAssign for AvrDuration
§Examples
let mut a = AvrDuration::new(16_000_000, 3_000);
a -= AvrDuration::new(16_000_000, 2_000);
assert_eq!(AvrDuration::new(16_000_000, 1_000), a);
let mut a = AvrDuration::new(16_000_000, 3_000);
a -= AvrDuration::new(16_000_000, 4_000);
assert_eq!(AvrDuration::new(16_000_000, 0), a);
impl SubAssign for AvrDuration
§Examples
let mut a = AvrDuration::new(16_000_000, 3_000);
a -= AvrDuration::new(16_000_000, 2_000);
assert_eq!(AvrDuration::new(16_000_000, 1_000), a);
let mut a = AvrDuration::new(16_000_000, 3_000);
a -= AvrDuration::new(16_000_000, 4_000);
assert_eq!(AvrDuration::new(16_000_000, 0), a);
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read more