pub struct ConcurrentShardedStack<T> { /* private fields */ }Expand description
Implementations§
Source§impl<T> ConcurrentShardedStack<T>
impl<T> ConcurrentShardedStack<T>
Sourcepub fn with_concurrency(shard_count: usize) -> Self
pub fn with_concurrency(shard_count: usize) -> Self
Creates a stack with exact shard count.
Panics if:
shard_count == 0shard_countis not power of two
Sourcepub fn push(&self, value: T) -> Result<(), PushError<T>>
pub fn push(&self, value: T) -> Result<(), PushError<T>>
Pushes a value into the stack.
Returns Err(PushError::Closed(value)) if this thread’s shard is closed.
While close is in progress, some shards may reject
pushes while others still accept them. After close returns, every
shard rejects pushes.
Sourcepub fn pop(&self) -> Result<T, PopError>
pub fn pop(&self) -> Result<T, PopError>
Pops a value from the stack non-blocking.
Scans the local shard first, then start ^ 1, start ^ 2, and so on.
Returns Err(PopError::Empty) if no element is found and at least one
shard is still observed open. This is not a consistent snapshot: other
threads can push into an already-scanned shard and drain a later shard,
so Empty can occur even if the stack was never globally empty during
the call. Consumers with active producers should retry rather than use
Empty as a completion signal.
Returns Err(PopError::Closed) if no element is found and every shard
is observed closed. Unlike Empty, this is terminal: closed shards
cannot receive more elements.
Sourcepub fn close(&self) -> bool
pub fn close(&self) -> bool
Closes every shard. Existing elements can still be popped.
Closure propagates one shard at a time. During the call, a push can be
rejected on one shard while a later push succeeds on another, and
is_closed can still return false after a rejected
push. Once this method returns, all shards are closed.
Returns true if this call closed at least one shard. Concurrent calls
can both return true; the result does not identify a unique closer.