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
sourceimpl From<OscTime> for SystemTime
impl From<OscTime> for SystemTime
sourcefn from(time: OscTime) -> SystemTime
fn from(time: OscTime) -> SystemTime
Converts to this type from the input type.
sourceimpl Ord for OscTime
impl Ord for OscTime
sourceimpl PartialOrd<OscTime> for OscTime
impl PartialOrd<OscTime> for OscTime
sourcefn partial_cmp(&self, other: &OscTime) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
sourceimpl TryFrom<SystemTime> for OscTime
impl TryFrom<SystemTime> for OscTime
type Error = OscTimeError
type Error = OscTimeError
The type returned in the event of a conversion error.
sourcefn try_from(time: SystemTime) -> Result<OscTime, OscTimeError>
fn try_from(time: SystemTime) -> Result<OscTime, OscTimeError>
Performs the conversion.
impl Copy for OscTime
impl Eq for OscTime
impl StructuralEq for OscTime
impl StructuralPartialEq for OscTime
Auto Trait Implementations
impl RefUnwindSafe for OscTime
impl Send for OscTime
impl Sync for OscTime
impl Unpin for OscTime
impl UnwindSafe for OscTime
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more