Timestamp

Struct Timestamp 

Source
pub struct Timestamp {
    pub seconds: u32,
    pub fraction: u32,
}
Expand description

High-precision timestamp for OpenIGTLink messages

The timestamp field in OpenIGTLink is a 64-bit value where:

  • Upper 32 bits: seconds since Unix epoch (UTC)
  • Lower 32 bits: fractional seconds in nanoseconds / 2^32

This provides nanosecond-level precision, critical for real-time tracking at 1000 Hz (1ms intervals).

Fields§

§seconds: u32

Seconds since Unix epoch (1970-01-01 00:00:00 UTC)

§fraction: u32

Fractional seconds as a 32-bit value (nanoseconds * 2^32 / 1_000_000_000)

Implementations§

Source§

impl Timestamp

Source

pub fn new(seconds: u32, fraction: u32) -> Self

Create a new timestamp from seconds and fraction

§Arguments
  • seconds - Seconds since Unix epoch
  • fraction - Fractional seconds (0x00000000 to 0xFFFFFFFF represents 0.0 to ~1.0)
Source

pub fn now() -> Self

Create a timestamp representing the current time

§Examples
use openigtlink_rust::protocol::header::Timestamp;

let ts = Timestamp::now();
assert!(ts.seconds > 0);
Source

pub fn zero() -> Self

Create a zero timestamp (no timestamp)

§Examples
use openigtlink_rust::protocol::header::Timestamp;

let ts = Timestamp::zero();
assert_eq!(ts.to_u64(), 0);
Source

pub fn to_u64(self) -> u64

Convert to OpenIGTLink wire format (u64)

Upper 32 bits: seconds, Lower 32 bits: fraction

Source

pub fn from_u64(value: u64) -> Self

Create from OpenIGTLink wire format (u64)

Upper 32 bits: seconds, Lower 32 bits: fraction

Source

pub fn to_nanos(self) -> u64

Convert to nanoseconds since Unix epoch

§Examples
use openigtlink_rust::protocol::header::Timestamp;

let ts = Timestamp::new(1000, 0x80000000); // 1000.5 seconds
assert_eq!(ts.to_nanos(), 1_000_500_000_000);
Source

pub fn from_nanos(nanos: u64) -> Self

Create from nanoseconds since Unix epoch

§Examples
use openigtlink_rust::protocol::header::Timestamp;

let ts = Timestamp::from_nanos(1_000_500_000_000); // 1000.5 seconds
assert_eq!(ts.seconds, 1000);
// Fraction should be approximately 0x80000000 (0.5)
assert!((ts.fraction as i64 - 0x80000000_i64).abs() < 100);
Source

pub fn to_f64(self) -> f64

Convert to floating-point seconds

§Examples
use openigtlink_rust::protocol::header::Timestamp;

let ts = Timestamp::new(1000, 0x80000000); // 1000.5 seconds
assert!((ts.to_f64() - 1000.5).abs() < 0.0001);

Trait Implementations§

Source§

impl Clone for Timestamp

Source§

fn clone(&self) -> Timestamp

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 Timestamp

Source§

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

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

impl PartialEq for Timestamp

Source§

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

Source§

impl Eq for Timestamp

Source§

impl StructuralPartialEq for Timestamp

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more