Struct Subscription

Source
pub struct Subscription<A, C, I>
where A: Allocator<C::Scalar>, C: Counter, I: Clone + Ord,
{ /* private fields */ }
Expand description

A subscription to a resource.

A subscription allows to perform continous allocations on a resource. A subscription is simply the combination of a resource and the user ID to perform accesses as. That is, a subscription can be created from a resource by providing the user ID to subscribe as. All subscriptions of different user IDs are distinct, but subscriptions with the same user ID reference the same underlying usage table.

To request resource from a resource registry, you have to subscribe to it first. This subscription is then used to request the resources in a charge. The subscription is pinned in every charge, so there is no need for the caller to cache it. However, if continuous charges are required, caching the subscription will skip a map lookup on every charge. Furthermore, as long as a subscription is alive, the underlying resource registry consider the subscriber to be interested in the resources. The resource allocation will thus be able to improve the fairness of the resource distribution, because it can better estimate how many users are interested in resources.

Implementations§

Source§

impl<A, C, I> Subscription<A, C, I>
where A: Allocator<C::Scalar>, C: Counter, I: Clone + Ord,

Source

pub fn charge( &self, slot: &C::Index, amount: &C::Scalar, ) -> Option<Charge<A, C, I>>

Create a new charge.

This is a shortcut for creating a new [Charge] object and calling [Charge::charge()]. If the charge request succeeds, this function returns the [Charge] object. Otherwise, None is returned.

Trait Implementations§

Source§

impl<A, C, I> Clone for Subscription<A, C, I>
where A: Allocator<C::Scalar>, C: Counter, I: Clone + Ord,

Source§

fn clone(&self) -> Self

Returns a copy 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<A, C, I> Drop for Subscription<A, C, I>
where A: Allocator<C::Scalar>, C: Counter, I: Clone + Ord,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<A, C, I> Freeze for Subscription<A, C, I>

§

impl<A, C, I> !RefUnwindSafe for Subscription<A, C, I>

§

impl<A, C, I> !Send for Subscription<A, C, I>

§

impl<A, C, I> !Sync for Subscription<A, C, I>

§

impl<A, C, I> Unpin for Subscription<A, C, I>

§

impl<A, C, I> !UnwindSafe for Subscription<A, C, I>

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.