Struct History

Source
pub struct History<T> { /* private fields */ }

Implementations§

Source§

impl<T> History<T>

Source

pub fn new(capacity: usize) -> History<T>

Source

pub fn push(&mut self, tick: u64, state: T) -> bool

Source

pub fn bracket(&self, tick: f64) -> Option<(&T, &T, f32)>

No extrapolation outside retained history: old/untrusted shot times are rejected.

Source

pub fn bracket_precise( &self, tick: u64, fraction: f64, endpoints: HistoryEndpointPolicy, minimum_newest_tick: Option<u64>, ) -> Result<HistoryBracket<'_, T>, HistoryQueryError>

Locate tick + fraction while comparing integer tick components exactly.

fraction must be finite and in [0, 1]. Exactly 1 carries to the next integer tick; negative zero is zero. (u64::MAX, 1) is an overflow error, while (u64::MAX, fraction < 1) is valid: a positive fraction there is after every possible sample. Invalid inputs are never silently clamped.

minimum_newest_tick is an optional inclusive freshness cutoff in the same nonwrapping authority/session tick domain as the stored samples. A host with supplied authority now_tick and an integer maximum age can pass Some(now_tick.saturating_sub(max_age_ticks)). None disables this check. The target tick is not assumed to be current server time. A cutoff cannot detect mismatched sessions or clock domains.

Precedence is input errors, empty, stale, then exact/interpolated/range placement. Freshness equality passes. The endpoint policy only affects out-of-range placement; it cannot override stale or invalid input.

Lookup takes O(log(len)) time across wrapped ring storage, allocates nothing and leaves history unchanged. Strict insertion order makes each interpolation gap positive. Subtraction occurs in ordered u64 values before conversion to f64, so short gaps at large ticks remain precise. Weights are approximate over wide gaps; use the outcome for identity, never alpha == 0 or alpha == 1. See the runnable module recipe.

Source

pub fn clear(&mut self)

Drop all retained states and forget insertion order, keeping allocated capacity.

On return, a lower tick may start a new session. Clear this history at the same reconnect boundary as crate::clock::ClientClock::reset and crate::clock::TickUnwrapper::reset, after excluding old-session traffic. Neither clearing nor tick unwrapping authenticates a session. Old samples cannot be recovered. A panic or side effect in T::drop is not rolled back; allocation-free reuse assumes the states’ destructors do not allocate. The module recipe demonstrates lower-tick reuse after reconnect.

Source

pub fn iter(&self) -> impl Iterator<Item = (u64, &T)>

Source

pub fn first_tick(&self) -> Option<u64>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> History<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for History<T>
where T: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for History<T>

§

impl<T> RefUnwindSafe for History<T>
where T: RefUnwindSafe,

§

impl<T> Send for History<T>
where T: Send,

§

impl<T> Sync for History<T>
where T: Sync,

§

impl<T> Unpin for History<T>
where T: Unpin,

§

impl<T> UnwindSafe for History<T>
where T: UnwindSafe,

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
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> 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.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.