pub struct Subsecond(/* private fields */);Expand description
A high-precision representation of subsecond time with attosecond resolution.
Subsecond stores time values less than one second using six components:
milliseconds, microseconds, nanoseconds, picoseconds, femtoseconds, and attoseconds.
Each component is normalized to the range [0, 999].
The total precision is 10⁻¹⁸ seconds (one attosecond), providing sufficient accuracy for astronomical and high-precision timing applications.
Implementations§
Source§impl Subsecond
impl Subsecond
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new Subsecond with all components set to zero.
§Examples
use lox_core::time::subsecond::Subsecond;
let s = Subsecond::new();
assert_eq!(s.as_attoseconds(), 0);Sourcepub const fn from_attoseconds(attoseconds: i64) -> Self
pub const fn from_attoseconds(attoseconds: i64) -> Self
Creates a Subsecond from a total number of attoseconds.
The input value is automatically normalized to the range [0, 10¹⁸) attoseconds (i.e., [0, 1) seconds). Values greater than or equal to one second wrap around, and negative values wrap from the top.
§Examples
use lox_core::time::subsecond::Subsecond;
let s = Subsecond::from_attoseconds(123456789123456789);
assert_eq!(s.milliseconds(), 123);
assert_eq!(s.microseconds(), 456);
assert_eq!(s.nanoseconds(), 789);
// Negative values wrap around
let s = Subsecond::from_attoseconds(-1);
assert_eq!(s.as_attoseconds(), 999999999999999999);Sourcepub const fn from_f64(value: f64) -> Option<Self>
pub const fn from_f64(value: f64) -> Option<Self>
Creates a Subsecond from an f64 value, extracting the fractional part.
Returns None if the value is not finite (NaN or infinite).
Sourcepub const fn set_milliseconds(self, milliseconds: u32) -> Self
pub const fn set_milliseconds(self, milliseconds: u32) -> Self
Sets the millisecond component (10⁻³ seconds).
Values are automatically normalized to [0, 999] using modulo arithmetic. In debug builds, values >= 1000 trigger an assertion.
§Examples
use lox_core::time::subsecond::Subsecond;
let s = Subsecond::new().set_milliseconds(123);
assert_eq!(s.milliseconds(), 123);Sourcepub const fn set_microseconds(self, microseconds: u32) -> Self
pub const fn set_microseconds(self, microseconds: u32) -> Self
Sets the microsecond component (10⁻⁶ seconds).
Values are automatically normalized to [0, 999] using modulo arithmetic. In debug builds, values >= 1000 trigger an assertion.
Sourcepub const fn set_nanoseconds(self, nanoseconds: u32) -> Self
pub const fn set_nanoseconds(self, nanoseconds: u32) -> Self
Sets the nanosecond component (10⁻⁹ seconds).
Values are automatically normalized to [0, 999] using modulo arithmetic. In debug builds, values >= 1000 trigger an assertion.
Sourcepub const fn set_picoseconds(self, picoseconds: u32) -> Self
pub const fn set_picoseconds(self, picoseconds: u32) -> Self
Sets the picosecond component (10⁻¹² seconds).
Values are automatically normalized to [0, 999] using modulo arithmetic. In debug builds, values >= 1000 trigger an assertion.
Sourcepub const fn set_femtoseconds(self, femtoseconds: u32) -> Self
pub const fn set_femtoseconds(self, femtoseconds: u32) -> Self
Sets the femtosecond component (10⁻¹⁵ seconds).
Values are automatically normalized to [0, 999] using modulo arithmetic. In debug builds, values >= 1000 trigger an assertion.
Sourcepub const fn set_attoseconds(self, attoseconds: u32) -> Self
pub const fn set_attoseconds(self, attoseconds: u32) -> Self
Sets the attosecond component (10⁻¹⁸ seconds).
Values are automatically normalized to [0, 999] using modulo arithmetic. In debug builds, values >= 1000 trigger an assertion.
Sourcepub const fn as_attoseconds(&self) -> i64
pub const fn as_attoseconds(&self) -> i64
Converts the subsecond value to total attoseconds.
§Examples
use lox_core::time::subsecond::Subsecond;
let s = Subsecond::new().set_milliseconds(123).set_microseconds(456);
assert_eq!(s.as_attoseconds(), 123456000000000000);Sourcepub const fn as_seconds_f64(&self) -> f64
pub const fn as_seconds_f64(&self) -> f64
Converts the subsecond value to seconds as an f64.
§Examples
use lox_core::time::subsecond::Subsecond;
let s = Subsecond::new().set_milliseconds(500);
assert_eq!(s.as_seconds_f64(), 0.5);Sourcepub const fn milliseconds(&self) -> u32
pub const fn milliseconds(&self) -> u32
Returns the millisecond component (10⁻³ seconds).
The returned value is always in the range [0, 999].
Sourcepub const fn microseconds(&self) -> u32
pub const fn microseconds(&self) -> u32
Returns the microsecond component (10⁻⁶ seconds).
The returned value is always in the range [0, 999].
Sourcepub const fn nanoseconds(&self) -> u32
pub const fn nanoseconds(&self) -> u32
Returns the nanosecond component (10⁻⁹ seconds).
The returned value is always in the range [0, 999].
Sourcepub const fn picoseconds(&self) -> u32
pub const fn picoseconds(&self) -> u32
Returns the picosecond component (10⁻¹² seconds).
The returned value is always in the range [0, 999].
Sourcepub const fn femtoseconds(&self) -> u32
pub const fn femtoseconds(&self) -> u32
Returns the femtosecond component (10⁻¹⁵ seconds).
The returned value is always in the range [0, 999].
Sourcepub const fn attoseconds(&self) -> u32
pub const fn attoseconds(&self) -> u32
Returns the attosecond component (10⁻¹⁸ seconds).
The returned value is always in the range [0, 999].