Struct AvrDuration

Source
pub struct AvrDuration { /* private fields */ }
Expand description

Implementations§

Source§

impl AvrDuration

Source

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.

Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

pub fn is_zero(self) -> bool

Returns whether the number of cycles contained by this duration is zero.

§Examples
let tt1 = AvrDuration::new(16_000_000, 0);
let tt2 = AvrDuration::new(16_000_000, 10_000);

assert!(tt1.is_zero());
assert!(!tt2.is_zero());

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,
);
Source§

type Output = AvrDuration

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
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);
Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for AvrDuration

Source§

fn clone(&self) -> AvrDuration

Returns a duplicate 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 AvrDuration

Source§

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

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

impl Display for AvrDuration

§Examples

let tt = AvrDuration::new(16_000_000, 0).add_millis(123);

assert_eq!("123000 µs", tt.to_string());
Source§

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

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

impl Hash for AvrDuration

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for AvrDuration

Source§

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

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

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl PartialEq for AvrDuration

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for AvrDuration

Source§

fn partial_cmp(&self, other: &AvrDuration) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
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,
);
Source§

type Output = AvrDuration

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
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);
Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl Copy for AvrDuration

Source§

impl Eq for AvrDuration

Source§

impl StructuralPartialEq for AvrDuration

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.