pub struct IndexAllocator { /* private fields */ }Expand description
Allocator for session indices within a single transport.
Manages a pool of random 32-bit indices, tracking which are in use to prevent collision. Thread-safe for single-threaded async use.
Implementations§
Source§impl IndexAllocator
impl IndexAllocator
Sourcepub fn with_max_attempts(max_attempts: usize) -> Self
pub fn with_max_attempts(max_attempts: usize) -> Self
Create with a specific max attempts limit.
Sourcepub fn allocate(&mut self) -> Result<SessionIndex, IndexError>
pub fn allocate(&mut self) -> Result<SessionIndex, IndexError>
Allocate a new random index.
Returns a cryptographically random 32-bit index that is not currently in use. Returns error if allocation fails after max_attempts tries (indicates too many active sessions).
Sourcepub fn free(&mut self, index: SessionIndex) -> Result<(), IndexError>
pub fn free(&mut self, index: SessionIndex) -> Result<(), IndexError>
Free an index, returning it to the available pool.
Returns error if the index was not allocated.
Sourcepub fn is_allocated(&self, index: SessionIndex) -> bool
pub fn is_allocated(&self, index: SessionIndex) -> bool
Check if an index is currently allocated.
Sourcepub fn reserve(&mut self, index: SessionIndex) -> Result<(), IndexError>
pub fn reserve(&mut self, index: SessionIndex) -> Result<(), IndexError>
Reserve a specific index (for testing or migration).
Returns error if the index is already in use.
Trait Implementations§
Source§impl Debug for IndexAllocator
impl Debug for IndexAllocator
Auto Trait Implementations§
impl Freeze for IndexAllocator
impl RefUnwindSafe for IndexAllocator
impl Send for IndexAllocator
impl Sync for IndexAllocator
impl Unpin for IndexAllocator
impl UnsafeUnpin for IndexAllocator
impl UnwindSafe for IndexAllocator
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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