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
impl Timestamp
Sourcepub fn new(seconds: u32, fraction: u32) -> Self
pub fn new(seconds: u32, fraction: u32) -> Self
Create a new timestamp from seconds and fraction
§Arguments
seconds
- Seconds since Unix epochfraction
- Fractional seconds (0x00000000 to 0xFFFFFFFF represents 0.0 to ~1.0)
Sourcepub fn now() -> Self
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);
Sourcepub fn zero() -> Self
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);
Sourcepub fn to_u64(self) -> u64
pub fn to_u64(self) -> u64
Convert to OpenIGTLink wire format (u64)
Upper 32 bits: seconds, Lower 32 bits: fraction
Sourcepub fn from_u64(value: u64) -> Self
pub fn from_u64(value: u64) -> Self
Create from OpenIGTLink wire format (u64)
Upper 32 bits: seconds, Lower 32 bits: fraction
Sourcepub fn to_nanos(self) -> u64
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);
Sourcepub fn from_nanos(nanos: u64) -> Self
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);
Trait Implementations§
impl Copy for Timestamp
impl Eq for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations§
impl Freeze for Timestamp
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnwindSafe for Timestamp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more