Skip to main content

BudgetedQueue

Struct BudgetedQueue 

Source
pub struct BudgetedQueue<T> { /* private fields */ }
Expand description

Represents budgeted queue.

Implementations§

Source§

impl<T> BudgetedQueue<T>

Source

pub fn new(budget: ResourceBudget) -> Self

Creates a new BudgetedQueue.

Source

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

Returns whether two handles refer to the same physical queue.

Source

pub fn try_push( &self, item: T, retained_bytes: usize, class: BudgetClass, ) -> QueuePushOutcome<T>

Attempts to push.

Source

pub fn try_push_budgeted( &self, item: T, permit: ResourcePermit, ) -> Result<QueuePushOutcome<T>, ForeignPermit<T>>

Pushes an item whose retained bytes are already charged by permit.

The permit is transferred into the queue, so an admission at the caller’s own ingress boundary and the queue retention charge the shared ancestor chain exactly once. A permit acquired from an ancestor of this queue’s budget is rebound to the queue before it is retained, which is the difference between this entry point and the ones that acquire their own permit from retained_bytes.

A rejection returns the item and releases the transferred charge, which matches the entry points that acquire their own permit: an item that was not retained holds no reservation.

§Errors

Returns ForeignPermit with the item and its unchanged permit when permit does not belong to this queue’s budget tree. The permit still holds the caller’s charge, so it is handed back instead of dropped.

Source

pub fn try_push_data( &self, item: T, retained_bytes: usize, ) -> QueuePushOutcome<T>

Attempts to push data.

Source

pub fn try_push_control( &self, item: T, retained_bytes: usize, ) -> QueuePushOutcome<T>

Attempts to push control.

Source

pub async fn push_until( &self, item: T, retained_bytes: usize, class: BudgetClass, deadline: Instant, ) -> QueuePushOutcome<T>

Pushes one item, waiting for count and byte capacity until an absolute Tokio deadline when this queue uses FullPolicy::WaitUntilDeadline.

Other full policies retain their existing immediate behavior. Rate exhaustion remains an immediate rejection because capacity-release notifications do not represent token refill time.

Every rejection contains the original item.

Source

pub fn try_pop(&self) -> Option<T>

Removes one item and releases its reservation before returning the payload.

Use Self::try_pop_budgeted when processing must retain the charge after the item leaves the queue.

Source

pub fn try_pop_budgeted(&self) -> Option<BudgetedItem<T>>

Removes one item while transferring its reservation to the caller.

The charge remains until the returned BudgetedItem or its permit is dropped, consumed, or rebound. Queue depth alone does not measure the number of outstanding reservations.

Source

pub fn retain(&self, keep: impl FnMut(&T) -> bool) -> usize

Retains queued items that satisfy keep and releases the resource permits owned by every removed item.

The relative order of retained items is preserved.

Source

pub async fn recv(&self) -> Option<T>

Asynchronously receives a payload, releasing its reservation on return.

Returns None after closed admission and queued work have drained.

Source

pub async fn recv_budgeted(&self) -> Option<BudgetedItem<T>>

Asynchronously receives an item with its reservation still attached.

Returns None after closed admission and queued work have drained. Cancellation of this wait does not consume a queued item.

Source

pub fn close(&self)

Executes close.

Source

pub fn is_closed(&self) -> bool

Returns whether closed.

Source

pub fn len(&self) -> usize

Returns the len.

Source

pub fn is_empty(&self) -> bool

Returns whether empty.

Source

pub fn snapshot(&self) -> QueueSnapshot

Returns the snapshot.

Trait Implementations§

Source§

impl<T> Clone for BudgetedQueue<T>

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<T> Debug for BudgetedQueue<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for BudgetedQueue<T>

§

impl<T> !UnwindSafe for BudgetedQueue<T>

§

impl<T> Freeze for BudgetedQueue<T>
where Arc<QueueInner<T>>: Freeze,

§

impl<T> Send for BudgetedQueue<T>
where Arc<QueueInner<T>>: Send,

§

impl<T> Sync for BudgetedQueue<T>
where Arc<QueueInner<T>>: Sync,

§

impl<T> Unpin for BudgetedQueue<T>
where Arc<QueueInner<T>>: Unpin,

§

impl<T> UnsafeUnpin for BudgetedQueue<T>
where Arc<QueueInner<T>>: UnsafeUnpin,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more