Skip to main content

SubscribeIdAllocator

Struct SubscribeIdAllocator 

Source
pub struct SubscribeIdAllocator {
    next_id: u64,
    max_id: u64,
}
Expand description

Allocates the Subscribe IDs this endpoint sends.

Section 8.6 defines the field: “Subscribe ID is a variable length integer that MUST be unique and monotonically increasing within a session and MUST be less than the session’s Maximum Subscribe ID.” SUBSCRIBE and FETCH draw from the same sequence, so one allocator serves both.

This draft states no parity rule - the client’s and the server’s ids are not separated by their least significant bit, as they are from draft-11 on - so the sequence simply starts at 0 and steps by one.

The ceiling is exclusive. Section 8.4 gives the Maximum Subscribe ID a starting value of 0 and reads that as “the peer MUST NOT create subscriptions”, which holds only if a ceiling of 0 forbids the id 0 as well.

The ceiling here is the one the peer granted this endpoint. The ceiling a peer’s ids are measured against is the one this endpoint advertised, which is a different number and lives on the endpoint rather than here.

Fields§

§next_id: u64§max_id: u64

Implementations§

Source§

impl SubscribeIdAllocator

Source

pub fn new() -> Self

Create an allocator starting at subscribe ID 0, blocked until a peer raises the maximum.

Source

pub fn allocate(&mut self) -> Result<VarInt, SubscribeIdError>

Allocate the next Subscribe ID.

§Errors

SubscribeIdError::Blocked if the next id would reach the ceiling.

Source

pub fn update_max(&mut self, new_max: u64) -> Result<(), SubscribeIdError>

Raise the maximum Subscribe ID this endpoint may use.

Section 8.4: “The Maximum Subscribe ID MUST only increase within a session, and receipt of a MAX_SUBSCRIBE_ID message with an equal or smaller Subscribe ID value is a ‘Protocol Violation’.”

§Errors

SubscribeIdError::Decreased if the value does not strictly increase.

Source

pub fn is_blocked(&self) -> bool

Whether the next allocation would reach the ceiling.

Source

pub fn max_id(&self) -> u64

The maximum Subscribe ID the peer has granted this endpoint.

Trait Implementations§

Source§

impl Default for SubscribeIdAllocator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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