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() -> Subsecond
pub const fn new() -> Subsecond
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) -> Subsecond
pub const fn from_attoseconds(attoseconds: i64) -> Subsecond
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);pub const fn from_f64(value: f64) -> Option<Subsecond>
Sourcepub const fn set_milliseconds(self, milliseconds: u32) -> Subsecond
pub const fn set_milliseconds(self, milliseconds: u32) -> Subsecond
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) -> Subsecond
pub const fn set_microseconds(self, microseconds: u32) -> Subsecond
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) -> Subsecond
pub const fn set_nanoseconds(self, nanoseconds: u32) -> Subsecond
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) -> Subsecond
pub const fn set_picoseconds(self, picoseconds: u32) -> Subsecond
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) -> Subsecond
pub const fn set_femtoseconds(self, femtoseconds: u32) -> Subsecond
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) -> Subsecond
pub const fn set_attoseconds(self, attoseconds: u32) -> Subsecond
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].
Trait Implementations§
Source§impl Ord for Subsecond
impl Ord for Subsecond
Source§impl PartialOrd for Subsecond
impl PartialOrd for Subsecond
impl Copy for Subsecond
impl Eq for Subsecond
Auto Trait Implementations§
impl Freeze for Subsecond
impl RefUnwindSafe for Subsecond
impl Send for Subsecond
impl Sync for Subsecond
impl Unpin for Subsecond
impl UnsafeUnpin for Subsecond
impl UnwindSafe for Subsecond
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more