pub struct RequestSequencer { /* private fields */ }core only.Expand description
Monotonic request id generator scoped to a single resource.
Each RequestSequencer produces a stream of RequestId values that are
unique within the resource’s lifetime. The sequence counter increments
from 1; when it would overflow u64::MAX, the scope advances to avoid
producing duplicate ids.
§Scope advancement
When the sequence counter reaches u64::MAX, next_request
calls advance_scope, which increments scope_id
and resets next_request_id to 1. This guarantees uniqueness across
the entire lifetime of the sequencer.
§Theoretical wrap-around
If scope_id itself overflows u64::MAX, it wraps back to 1 and
next_request_id is reset to 1. This means a new RequestId(1, 1) could
theoretically collide with a very old RequestId(1, 1) still held by a
long-running future. In practice, reaching u64::MAX requests per scope
is essentially impossible, so this is not a practical concern. For
extremely long-lived processes (e.g., a server running for decades), the
collision risk remains theoretical but documented here for completeness.
Implementations§
Source§impl RequestSequencer
impl RequestSequencer
Sourcepub fn next_request(&mut self) -> RequestId
pub fn next_request(&mut self) -> RequestId
Generate the next request id.
The sequence counter increments with each call. When it reaches
u64::MAX, the scope advances automatically before the next call
produces a duplicate.
Sourcepub fn advance_scope(&mut self)
pub fn advance_scope(&mut self)
Advance to a new scope when the sequence overflows.
Increments scope_id via checked addition. If scope_id itself
overflows (astronomically unlikely), it wraps to 1 and the sequence
resets, as documented on the struct.
Sourcepub fn is_current_scope(&self, request_id: RequestId) -> bool
pub fn is_current_scope(&self, request_id: RequestId) -> bool
Whether the given request id belongs to the current scope.
Trait Implementations§
Source§impl Clone for RequestSequencer
impl Clone for RequestSequencer
Source§fn clone(&self) -> RequestSequencer
fn clone(&self) -> RequestSequencer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RequestSequencer
impl Debug for RequestSequencer
Source§impl Default for RequestSequencer
impl Default for RequestSequencer
Source§impl<'de> Deserialize<'de> for RequestSequencer
impl<'de> Deserialize<'de> for RequestSequencer
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for RequestSequencer
Source§impl PartialEq for RequestSequencer
impl PartialEq for RequestSequencer
Source§impl Serialize for RequestSequencer
impl Serialize for RequestSequencer
impl StructuralPartialEq for RequestSequencer
Auto Trait Implementations§
impl Freeze for RequestSequencer
impl RefUnwindSafe for RequestSequencer
impl Send for RequestSequencer
impl Sync for RequestSequencer
impl Unpin for RequestSequencer
impl UnsafeUnpin for RequestSequencer
impl UnwindSafe for RequestSequencer
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().