pub struct Timedelta(/* private fields */);Expand description
A signed span of nanoseconds: how far apart two points on one timeline are.
Its operators saturate at MIN and MAX, about 292 years either
way, and each has a checked_* twin. It is written coarsest unit first, the way a config spells
it, and parses back from the same spelling.
§Examples
use t2t_core::Timedelta;
let budget = Timedelta::from_millis(250);
assert_eq!(budget.as_micros(), 250_000, "the same span, counted finer");
assert_eq!(budget.to_string(), "250ms", "written in its coarsest unit");
assert_eq!("1m0s250ms".parse(), Ok(Timedelta::MINUTE + budget), "and read back");Implementations§
Source§impl Timedelta
impl Timedelta
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Whether the span runs backwards.
Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Whether the span runs forwards.
Sourcepub const fn checked_add(self, other: Self) -> Option<Self>
pub const fn checked_add(self, other: Self) -> Option<Self>
The sum, or None past the range.
Sourcepub const fn checked_sub(self, other: Self) -> Option<Self>
pub const fn checked_sub(self, other: Self) -> Option<Self>
The difference, or None past the range.
Sourcepub const fn checked_mul(self, factor: i64) -> Option<Self>
pub const fn checked_mul(self, factor: i64) -> Option<Self>
The span factor times over, or None past the range.
Sourcepub const fn checked_div(self, parts: i64) -> Option<Self>
pub const fn checked_div(self, parts: i64) -> Option<Self>
One of parts equal parts, truncated toward zero, or None for no parts, or for
MIN in -1.
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
The span backwards, or None for MIN.
Sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
The span forwards, or None for MIN.
Source§impl Timedelta
impl Timedelta
Sourcepub const NANOSECOND: Self
pub const NANOSECOND: Self
One nanosecond, the finest span the count resolves.
Sourcepub const MICROSECOND: Self
pub const MICROSECOND: Self
One microsecond.
Sourcepub const MILLISECOND: Self
pub const MILLISECOND: Self
One millisecond.
Sourcepub const fn from_nanos(nanos: i64) -> Self
pub const fn from_nanos(nanos: i64) -> Self
A span of nanos nanoseconds.
Sourcepub const fn from_micros(micros: i64) -> Self
pub const fn from_micros(micros: i64) -> Self
A span of micros microseconds, saturating.
Sourcepub const fn from_millis(millis: i64) -> Self
pub const fn from_millis(millis: i64) -> Self
A span of millis milliseconds, saturating.
Sourcepub const fn from_hours(hours: i64) -> Self
pub const fn from_hours(hours: i64) -> Self
A span of hours hours, saturating.
Sourcepub const fn subsec_nanos(self) -> i32
pub const fn subsec_nanos(self) -> i32
The nanoseconds past the whole seconds, signed as the span is.
Sourcepub const fn subsec_micros(self) -> i32
pub const fn subsec_micros(self) -> i32
The whole microseconds past the whole seconds, signed as the span is.
Sourcepub const fn subsec_millis(self) -> i32
pub const fn subsec_millis(self) -> i32
The whole milliseconds past the whole seconds, signed as the span is.
Sourcepub const fn to_tickdelta(self, rate: TickRate) -> Tickdelta
pub const fn to_tickdelta(self, rate: TickRate) -> Tickdelta
How many ticks the span lasts at rate: a multiply and a shift, to within a tick.
Trait Implementations§
Source§impl Add<Timedelta> for TaiTimestamp
impl Add<Timedelta> for TaiTimestamp
Source§impl Add<Timedelta> for BootUptime
impl Add<Timedelta> for BootUptime
Source§impl AddAssign for Timedelta
impl AddAssign for Timedelta
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read moreSource§impl AddAssign<Timedelta> for Timestamp
impl AddAssign<Timedelta> for Timestamp
Source§fn add_assign(&mut self, span: Timedelta)
fn add_assign(&mut self, span: Timedelta)
+= operation. Read moreSource§impl AddAssign<Timedelta> for TaiTimestamp
impl AddAssign<Timedelta> for TaiTimestamp
Source§fn add_assign(&mut self, span: Timedelta)
fn add_assign(&mut self, span: Timedelta)
+= operation. Read moreSource§impl AddAssign<Timedelta> for Uptime
impl AddAssign<Timedelta> for Uptime
Source§fn add_assign(&mut self, span: Timedelta)
fn add_assign(&mut self, span: Timedelta)
+= operation. Read moreSource§impl AddAssign<Timedelta> for RawUptime
impl AddAssign<Timedelta> for RawUptime
Source§fn add_assign(&mut self, span: Timedelta)
fn add_assign(&mut self, span: Timedelta)
+= operation. Read moreSource§impl AddAssign<Timedelta> for BootUptime
impl AddAssign<Timedelta> for BootUptime
Source§fn add_assign(&mut self, span: Timedelta)
fn add_assign(&mut self, span: Timedelta)
+= operation. Read moreimpl Copy for Timedelta
Source§impl<'de> Deserialize<'de> for Timedelta
impl<'de> Deserialize<'de> for Timedelta
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Display for Timedelta
Coarsest unit first, once each, 0s for zero: 1d2h, 1m0s250ms, -3us.
impl Display for Timedelta
Coarsest unit first, once each, 0s for zero: 1d2h, 1m0s250ms, -3us.
impl Eq for Timedelta
Source§impl From<Timedelta> for TimeDelta
Every span, since a TimeDelta holds every i64 of nanoseconds.
impl From<Timedelta> for TimeDelta
Every span, since a TimeDelta holds every i64 of nanoseconds.
Source§impl From<Timedelta> for SignedDuration
Every span, since a SignedDuration holds every i64 of nanoseconds.
impl From<Timedelta> for SignedDuration
Every span, since a SignedDuration holds every i64 of nanoseconds.
Source§impl From<Timedelta> for Duration
Every span, since a Duration holds every i64 of nanoseconds.
impl From<Timedelta> for Duration
Every span, since a Duration holds every i64 of nanoseconds.
Source§impl FromBytes for Timedeltawhere
i64: FromBytes,
impl FromBytes for Timedeltawhere
i64: FromBytes,
§fn ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>where
Self: KnownLayout + Immutable,
fn ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>where
Self: KnownLayout + Immutable,
§fn ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>where
Self: KnownLayout + Immutable,
fn ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>where
Self: KnownLayout + Immutable,
§fn ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>where
Self: Immutable + KnownLayout,
fn ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>where
Self: Immutable + KnownLayout,
&Self. Read more§fn mut_from_bytes(
source: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, !>>where
Self: IntoBytes + KnownLayout,
fn mut_from_bytes(
source: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, !>>where
Self: IntoBytes + KnownLayout,
§fn mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, !>>where
Self: IntoBytes + KnownLayout,
fn mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, !>>where
Self: IntoBytes + KnownLayout,
§fn mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, !>>where
Self: IntoBytes + KnownLayout,
fn mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, !>>where
Self: IntoBytes + KnownLayout,
§fn read_from_prefix(
source: &[u8],
) -> Result<(Self, &[u8]), SizeError<&[u8], Self>>where
Self: Sized,
fn read_from_prefix(
source: &[u8],
) -> Result<(Self, &[u8]), SizeError<&[u8], Self>>where
Self: Sized,
Source§impl FromStr for Timedelta
Reads what Display writes, and the bare 0: each unit at most once and
coarsest first, with any count in each, so 48h reads as the span 2d spells.
impl FromStr for Timedelta
Reads what Display writes, and the bare 0: each unit at most once and
coarsest first, with any count in each, so 48h reads as the span 2d spells.
Source§impl FromZeros for Timedeltawhere
i64: FromZeros,
impl FromZeros for Timedeltawhere
i64: FromZeros,
§fn new_zeroed() -> Selfwhere
Self: Sized,
fn new_zeroed() -> Selfwhere
Self: Sized,
Self from zeroed bytes. Read more§fn new_box_zeroed() -> Result<Box<Self>, AllocError>where
Self: Sized,
fn new_box_zeroed() -> Result<Box<Self>, AllocError>where
Self: Sized,
Box<Self> from zeroed bytes. Read more§fn new_vec_zeroed(len: usize) -> Result<Vec<Self>, AllocError>where
Self: Sized,
fn new_vec_zeroed(len: usize) -> Result<Vec<Self>, AllocError>where
Self: Sized,
Vec<Self> from zeroed bytes. Read moreimpl Immutable for Timedeltawhere
i64: Immutable,
Source§impl IntoBytes for Timedeltawhere
i64: IntoBytes,
impl IntoBytes for Timedeltawhere
i64: IntoBytes,
§fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
§fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
§fn write_to_prefix(
&self,
dst: &mut [u8],
) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
fn write_to_prefix(
&self,
dst: &mut [u8],
) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
Source§impl JsonSchema for Timedelta
impl JsonSchema for Timedelta
Source§fn json_schema(_generator: &mut SchemaGenerator) -> Schema
fn json_schema(_generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl KnownLayout for Timedeltawhere
Self: Sized,
impl KnownLayout for Timedeltawhere
Self: Sized,
Source§type PointerMetadata = ()
type PointerMetadata = ()
Self. Read more§fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>
fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>
Self with the given pointer
metadata. Read moreSource§impl MulAssign<i64> for Timedelta
impl MulAssign<i64> for Timedelta
Source§fn mul_assign(&mut self, factor: i64)
fn mul_assign(&mut self, factor: i64)
*= operation. Read moreSource§impl Ord for Timedelta
impl Ord for Timedelta
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Timedelta
impl PartialOrd for Timedelta
impl StructuralPartialEq for Timedelta
Source§impl Sub<Timedelta> for TaiTimestamp
impl Sub<Timedelta> for TaiTimestamp
Source§impl Sub<Timedelta> for BootUptime
impl Sub<Timedelta> for BootUptime
Source§impl SubAssign for Timedelta
impl SubAssign for Timedelta
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-= operation. Read moreSource§impl SubAssign<Timedelta> for Timestamp
impl SubAssign<Timedelta> for Timestamp
Source§fn sub_assign(&mut self, span: Timedelta)
fn sub_assign(&mut self, span: Timedelta)
-= operation. Read moreSource§impl SubAssign<Timedelta> for TaiTimestamp
impl SubAssign<Timedelta> for TaiTimestamp
Source§fn sub_assign(&mut self, span: Timedelta)
fn sub_assign(&mut self, span: Timedelta)
-= operation. Read moreSource§impl SubAssign<Timedelta> for Uptime
impl SubAssign<Timedelta> for Uptime
Source§fn sub_assign(&mut self, span: Timedelta)
fn sub_assign(&mut self, span: Timedelta)
-= operation. Read moreSource§impl SubAssign<Timedelta> for RawUptime
impl SubAssign<Timedelta> for RawUptime
Source§fn sub_assign(&mut self, span: Timedelta)
fn sub_assign(&mut self, span: Timedelta)
-= operation. Read moreSource§impl SubAssign<Timedelta> for BootUptime
impl SubAssign<Timedelta> for BootUptime
Source§fn sub_assign(&mut self, span: Timedelta)
fn sub_assign(&mut self, span: Timedelta)
-= operation. Read moreSource§impl TryFrom<SignedDuration> for Timedelta
Refuses a duration past Timedelta::MIN or Timedelta::MAX.
impl TryFrom<SignedDuration> for Timedelta
Refuses a duration past Timedelta::MIN or Timedelta::MAX.
Source§impl TryFrom<SignedDuration> for Timedelta
Refuses a duration past Timedelta::MIN or Timedelta::MAX.
impl TryFrom<SignedDuration> for Timedelta
Refuses a duration past Timedelta::MIN or Timedelta::MAX.
Source§impl TryFrom<TimeDelta> for Timedelta
Refuses a duration past Timedelta::MIN or Timedelta::MAX.
impl TryFrom<TimeDelta> for Timedelta
Refuses a duration past Timedelta::MIN or Timedelta::MAX.