Struct nannou_osc::Time

source ·
pub struct Time {
    pub seconds: u32,
    pub fractional: u32,
}
Expand description

A time tag in OSC message consists of two 32-bit integers where the first one denotes the number of seconds since 1900-01-01 and the second the fractions of a second. For details on its semantics see http://opensoundcontrol.org/node/3/#timetags

Examples

#[cfg(feature = "std")]
{
    use rosc::OscTime;
    use std::{convert::TryFrom, time::UNIX_EPOCH};

    assert_eq!(
        OscTime::try_from(UNIX_EPOCH).unwrap(),
        OscTime::from((2_208_988_800, 0))
    );
}

Conversions between (u32, u32)

Prior to version 0.5.0 of this crate, OscTime was defined as a type alias to (u32, u32). If you are upgrading from one of these older versions, you can use .into() to convert between (u32, u32) and OscTime in either direction.

Conversions between std::time::SystemTime

The traits in std::convert are implemented for converting between SystemTime and OscTime in both directions. An OscTime can be converted into a SystemTime using From/Into. A SystemTime can be converted into an OscTime using TryFrom/TryInto. The fallible variants of the conversion traits are used this case because not every SystemTime can be represented as an OscTime.

These conversions are lossy, but are tested to have a deviation within 5 nanoseconds when converted back and forth in either direction.

Although any time since the OSC epoch (1900-01-01 00:00:00 UTC) can be represented using the OSC timestamp format, this crate only allows conversions between times greater than or equal to the UNIX_EPOCH. This allows the math used in the conversions to work on 32-bit systems which cannot represent times that far back.

Fields§

§seconds: u32§fractional: u32

Trait Implementations§

source§

impl Clone for OscTime

source§

fn clone(&self) -> OscTime

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 OscTime

source§

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

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

impl From<(u32, u32)> for OscTime

source§

fn from(time: (u32, u32)) -> OscTime

Converts to this type from the input type.
source§

impl Hash for OscTime

source§

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

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 OscTime

source§

fn cmp(&self, other: &OscTime) -> 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 + PartialOrd,

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

impl PartialEq for OscTime

source§

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

source§

fn partial_cmp(&self, other: &OscTime) -> 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 TryFrom<SystemTime> for OscTime

§

type Error = OscTimeError

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

fn try_from(time: SystemTime) -> Result<OscTime, OscTimeError>

Performs the conversion.
source§

impl Copy for OscTime

source§

impl Eq for OscTime

source§

impl StructuralEq for OscTime

source§

impl StructuralPartialEq for OscTime

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> 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,

§

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