Skip to main content

PublishStateMachine

Struct PublishStateMachine 

Source
pub struct PublishStateMachine {
    state: PublishState,
}
Expand description

Pure state machine for a subscription a PUBLISH opened. Transitions: Idle -> Publishing -> Active -> Done.

The two ends of the flow are the two halves of Section 4.1’s sentence: “A subscriber MUST send exactly one PUBLISH_OK or PUBLISH_ERROR in response to a PUBLISH”, and “the subscription can be … terminated by the subscriber using UNSUBSCRIBE, or terminated by the publisher using SUBSCRIBE_DONE”. Each event has a transition of its own even where two of them land in the same state, so that a refusal names the event that was refused, and so that each direction of the flow names its own half of it.

Fields§

§state: PublishState

Implementations§

Source§

impl PublishStateMachine

Source

pub fn new() -> Self

Creates a new state machine in the PublishState::Idle state.

Source

pub fn state(&self) -> PublishState

Returns the current state of the subscription.

Source

fn step( &mut self, from: PublishState, to: PublishState, event: &str, ) -> Result<(), PublishError>

Source

pub fn on_publish_received(&mut self) -> Result<(), PublishError>

Idle -> Publishing (PUBLISH received from the peer).

Source

pub fn on_publish_ok_sent(&mut self) -> Result<(), PublishError>

Publishing -> Active (this endpoint answered PUBLISH_OK).

Source

pub fn on_publish_error_sent(&mut self) -> Result<(), PublishError>

Publishing -> Done (this endpoint answered PUBLISH_ERROR).

Source

pub fn on_unsubscribe_sent(&mut self) -> Result<(), PublishError>

Active -> Done (this endpoint sent UNSUBSCRIBE).

Only from Active: the draft gives the subscriber UNSUBSCRIBE for a subscription that is established, and a PUBLISH it has not answered yet is refused with PUBLISH_ERROR instead.

Source

pub fn on_subscribe_done_received(&mut self) -> Result<(), PublishError>

Active -> Done (the publishing peer sent SUBSCRIBE_DONE).

Source

pub fn on_publish_sent(&mut self) -> Result<(), PublishError>

Idle -> Publishing (PUBLISH sent to the peer).

The mirror of Self::on_publish_received, and the same step: Section 4.1 opens with “A subscription can be initiated by either a publisher or a subscriber”, so an offer looks the same from both ends and only the event name says which end made it.

Source

pub fn on_publish_ok(&mut self) -> Result<(), PublishError>

Publishing -> Active (the subscribing peer answered PUBLISH_OK).

Source

pub fn on_publish_error(&mut self) -> Result<(), PublishError>

Publishing -> Done (the subscribing peer answered PUBLISH_ERROR).

The offer is over rather than pending. Section 4.1: “Objects MUST NOT be sent for requests that end with an error.”

Source

pub fn on_subscribe_done_sent(&mut self) -> Result<(), PublishError>

Active -> Done (this endpoint, as the publisher, sent SUBSCRIBE_DONE).

Source

pub fn on_unsubscribe_received(&mut self) -> Result<(), PublishError>

Active -> Done (the subscribing peer sent UNSUBSCRIBE).

The mirror of Self::on_unsubscribe_sent and the same step, on a subscription this endpoint opened rather than one it took. Section 8.11 gives the message to the subscriber alone, so which end sends it follows from which end made the offer.

Trait Implementations§

Source§

impl Default for PublishStateMachine

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