Skip to main content

Tickdelta

Struct Tickdelta 

Source
pub struct Tickdelta(/* private fields */);
Expand description

A signed span of counter ticks: how far apart two Tickstamps are.

Its operators saturate, each with a checked_* twin, as a Timedelta’s do; a TickRate turns it into one. It is written as its count, 24 ticks, and parses back from it.

§Examples

use t2t_core::{TickRate, Tickdelta, Timedelta};

let span: Tickdelta = "3000 ticks".parse()?;
let rate = TickRate::from_hertz(3_000_000_000).expect("a nonzero rate");
assert_eq!(span.to_timedelta(rate), Timedelta::MICROSECOND, "3000 ticks at 3 GHz");

Implementations§

Source§

impl Tickdelta

Source

pub const ZERO: Self

No time at all.

Source

pub const MIN: Self

The longest span backwards.

Source

pub const MAX: Self

The longest span.

Source

pub const fn is_zero(self) -> bool

Whether the span is zero.

Source

pub const fn is_negative(self) -> bool

Whether the span runs backwards.

Source

pub const fn is_positive(self) -> bool

Whether the span runs forwards.

Source

pub const fn abs(self) -> Self

The span forwards, MAX for MIN.

Source

pub const fn checked_add(self, other: Self) -> Option<Self>

The sum, or None past the range.

Source

pub const fn checked_sub(self, other: Self) -> Option<Self>

The difference, or None past the range.

Source

pub const fn checked_mul(self, factor: i64) -> Option<Self>

The span factor times over, or None past the range.

Source

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.

Source

pub const fn checked_neg(self) -> Option<Self>

The span backwards, or None for MIN.

Source

pub const fn checked_abs(self) -> Option<Self>

The span forwards, or None for MIN.

Source

pub const fn floor(self, unit: Self) -> Self

The nearest multiple of |unit| at or below the span, or the span for a zero unit.

Source

pub const fn ceil(self, unit: Self) -> Self

The nearest multiple of |unit| at or above the span, or the span for a zero unit.

Source§

impl Tickdelta

Source

pub const fn from_ticks(ticks: i64) -> Self

A span of ticks ticks.

Source

pub const fn as_ticks(self) -> i64

The span in ticks.

Source

pub const fn to_timedelta(self, rate: TickRate) -> Timedelta

How long the span lasts at rate: a multiply and a shift, to within a nanosecond.

Trait Implementations§

Source§

impl Add for Tickdelta

Saturates at MIN and MAX.

Source§

type Output = Tickdelta

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl Add<Tickdelta> for Tickstamp

Saturates at MIN and MAX.

Source§

type Output = Tickstamp

The resulting type after applying the + operator.
Source§

fn add(self, span: Tickdelta) -> Self

Performs the + operation. Read more
Source§

impl AddAssign for Tickdelta

Saturates at MIN and MAX.

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl AddAssign<Tickdelta> for Tickstamp

Saturates at MIN and MAX.

Source§

fn add_assign(&mut self, span: Tickdelta)

Performs the += operation. Read more
Source§

impl Clone for Tickdelta

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Tickdelta

Source§

impl Debug for Tickdelta

Source§

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

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

impl Default for Tickdelta

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Tickdelta

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Tickdelta

Source§

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

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

impl Eq for Tickdelta

Source§

impl FromBytes for Tickdelta
where i64: FromBytes,

§

fn ref_from_bytes( source: &[u8], ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>
where Self: KnownLayout + Immutable,

Interprets the given source as a &Self. Read more
§

fn ref_from_prefix( source: &[u8], ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>
where Self: KnownLayout + Immutable,

Interprets the prefix of the given source as a &Self without copying. Read more
§

fn ref_from_suffix( source: &[u8], ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>
where Self: Immutable + KnownLayout,

Interprets the suffix of the given bytes as a &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,

Interprets the given source as a &mut Self. Read more
§

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,

Interprets the prefix of the given source as a &mut Self without copying. Read more
§

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,

Interprets the suffix of the given source as a &mut Self without copying. Read more
§

fn read_from_bytes(source: &[u8]) -> Result<Self, SizeError<&[u8], Self>>
where Self: Sized,

Reads a copy of Self from the given source. Read more
§

fn read_from_prefix( source: &[u8], ) -> Result<(Self, &[u8]), SizeError<&[u8], Self>>
where Self: Sized,

Reads a copy of Self from the prefix of the given source. Read more
§

fn read_from_suffix( source: &[u8], ) -> Result<(&[u8], Self), SizeError<&[u8], Self>>
where Self: Sized,

Reads a copy of Self from the suffix of the given source. Read more
§

fn read_from_io<R>(src: R) -> Result<Self, Error>
where Self: Sized, R: Read,

Reads a copy of self from an io::Read. Read more
Source§

impl FromStr for Tickdelta

Reads what Display writes: a count, then ticks.

Source§

type Err = ParseTickdeltaError

The associated error which can be returned from parsing.
Source§

fn from_str(text: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl FromZeros for Tickdelta
where i64: FromZeros,

§

fn zero(&mut self)

Overwrites self with zeros. Read more
§

fn new_zeroed() -> Self
where Self: Sized,

Creates an instance of Self from zeroed bytes. Read more
§

fn new_box_zeroed() -> Result<Box<Self>, AllocError>
where Self: Sized,

Creates a Box<Self> from zeroed bytes. Read more
§

fn new_vec_zeroed(len: usize) -> Result<Vec<Self>, AllocError>
where Self: Sized,

Creates a Vec<Self> from zeroed bytes. Read more
§

fn extend_vec_zeroed( v: &mut Vec<Self>, additional: usize, ) -> Result<(), AllocError>
where Self: Sized,

Extends a Vec<Self> by pushing additional new items onto the end of the vector. The new items are initialized with zeros.
§

fn insert_vec_zeroed( v: &mut Vec<Self>, position: usize, additional: usize, ) -> Result<(), AllocError>
where Self: Sized,

Inserts additional new items into Vec<Self> at position. The new items are initialized with zeros. Read more
Source§

impl Hash for Tickdelta

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Immutable for Tickdelta
where i64: Immutable,

Source§

impl IntoBytes for Tickdelta
where i64: IntoBytes,

§

fn as_bytes(&self) -> &[u8] ⓘ
where Self: Immutable,

Gets the bytes of this value. Read more
§

fn as_mut_bytes(&mut self) -> &mut [u8] ⓘ
where Self: FromBytes,

Gets the bytes of this value mutably. Read more
§

fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to dst. Read more
§

fn write_to_prefix( &self, dst: &mut [u8], ) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to the prefix of dst. Read more
§

fn write_to_suffix( &self, dst: &mut [u8], ) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to the suffix of dst. Read more
§

fn write_to_io<W>(&self, dst: W) -> Result<(), Error>
where Self: Immutable, W: Write,

Writes a copy of self to an io::Write. Read more
Source§

impl JsonSchema for Tickdelta

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn json_schema(_generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

impl KnownLayout for Tickdelta
where Self: Sized,

Source§

type PointerMetadata = ()

The type of metadata stored in a pointer to Self. Read more
§

fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>

Computes the size of an object of type Self with the given pointer metadata. Read more
Source§

impl Mul<Tickdelta> for i64

Saturates at the span’s range.

Source§

type Output = Tickdelta

The resulting type after applying the * operator.
Source§

fn mul(self, span: Tickdelta) -> Tickdelta

Performs the * operation. Read more
Source§

impl Mul<i64> for Tickdelta

Saturates at MIN and MAX.

Source§

type Output = Tickdelta

The resulting type after applying the * operator.
Source§

fn mul(self, factor: i64) -> Self

Performs the * operation. Read more
Source§

impl MulAssign<i64> for Tickdelta

Saturates at MIN and MAX.

Source§

fn mul_assign(&mut self, factor: i64)

Performs the *= operation. Read more
Source§

impl Neg for Tickdelta

MAX for MIN.

Source§

type Output = Tickdelta

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl Ord for Tickdelta

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Tickdelta

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Tickdelta

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Tickdelta

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Tickdelta

Source§

impl Sub for Tickdelta

Saturates at MIN and MAX.

Source§

type Output = Tickdelta

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
Source§

impl Sub<Tickdelta> for Tickstamp

Saturates at MIN and MAX.

Source§

type Output = Tickstamp

The resulting type after applying the - operator.
Source§

fn sub(self, span: Tickdelta) -> Self

Performs the - operation. Read more
Source§

impl SubAssign for Tickdelta

Saturates at MIN and MAX.

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl SubAssign<Tickdelta> for Tickstamp

Saturates at MIN and MAX.

Source§

fn sub_assign(&mut self, span: Tickdelta)

Performs the -= operation. Read more
Source§

impl Sum for Tickdelta

Saturates at MIN and MAX.

Source§

fn sum<I: Iterator<Item = Self>>(spans: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<'a> Sum<&'a Tickdelta> for Tickdelta

Saturates at MIN and MAX.

Source§

fn sum<I: Iterator<Item = &'a Self>>(spans: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl TryFromBytes for Tickdelta
where i64: TryFromBytes,

§

fn try_ref_from_bytes( source: &[u8], ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the given source as a &Self. Read more
§

fn try_ref_from_prefix( source: &[u8], ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the prefix of the given source as a &Self. Read more
§

fn try_ref_from_suffix( source: &[u8], ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the suffix of the given source as a &Self. Read more
§

fn try_mut_from_bytes( bytes: &mut [u8], ) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the given source as a &mut Self without copying. Read more
§

fn try_mut_from_prefix( source: &mut [u8], ) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the prefix of the given source as a &mut Self. Read more
§

fn try_mut_from_suffix( source: &mut [u8], ) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the suffix of the given source as a &mut Self. Read more
§

fn try_read_from_bytes( source: &[u8], ) -> Result<Self, ConvertError<!, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: Sized,

Attempts to read the given source as a Self. Read more
§

fn try_read_from_prefix( source: &[u8], ) -> Result<(Self, &[u8]), ConvertError<!, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: Sized,

Attempts to read a Self from the prefix of the given source. Read more
§

fn try_read_from_suffix( source: &[u8], ) -> Result<(&[u8], Self), ConvertError<!, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: Sized,

Attempts to read a Self from the suffix of the given source. Read more

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

§

impl<A, T> Read<A, BecauseImmutable> for T
where A: Aliasing, T: Immutable + ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.