Skip to main content

Protocol

Struct Protocol 

Source
pub struct Protocol { /* private fields */ }
Expand description

Pure Phoenix Channels protocol state.

The caller owns I/O, clocks, authentication refresh, and retry scheduling. That makes the same state machine usable from browser WASM, Tokio, smol, or a UI framework executor.

Implementations§

Source§

impl Protocol

Source

pub fn new() -> Self

Creates empty protocol state.

Source

pub fn channel_state(&self, topic: &str) -> Option<ChannelState>

Returns the local state of topic, if it is known.

Source

pub fn join( &mut self, topic: impl Into<String>, params: Value, ) -> Result<Outbound, ProtocolError>

Starts joining a topic with the supplied parameters.

The returned frame must be sent and later passed back through Protocol::receive when its reply arrives.

Source

pub fn rejoin( &mut self, topic: impl Into<String>, refreshed_params: Value, ) -> Result<Outbound, ProtocolError>

Starts a new join generation for a disconnected, errored, or closed topic.

Source

pub fn rejoin_all_with_stored_params(&mut self) -> Vec<Outbound>

Rejoins every inactive topic using the parameters stored by its prior join.

Source

pub fn leave(&mut self, topic: &str) -> Result<Outbound, ProtocolError>

Starts leaving a joined topic.

Source

pub fn push( &mut self, topic: &str, event: impl Into<String>, payload: impl Into<Payload>, ) -> Result<Outbound, ProtocolError>

Builds and tracks an application push that expects a reply.

Source

pub fn cast( &self, topic: &str, event: impl Into<String>, payload: impl Into<Payload>, ) -> Result<Frame, ProtocolError>

Builds a push that does not request a reply.

The frame has no ref, so it is not tracked as an in-flight request.

Source

pub fn forget_push(&mut self, reference: &str) -> bool

Stops correlating a push reply, for example after an API timeout.

Join and leave requests cannot be forgotten through this method because their replies also transition channel state.

Source

pub fn forget_heartbeat(&mut self, reference: &str) -> bool

Stops correlating a heartbeat reply, for example after an explicit ping has timed out at the client API boundary.

Source

pub fn discard_channel(&mut self, topic: &str) -> bool

Removes all local state associated with a topic.

This is used when a channel handle is dropped. Any later replies for the removed join generation are treated as unmatched messages.

Source

pub fn heartbeat(&mut self) -> Outbound

Builds and tracks a Phoenix heartbeat.

Source

pub fn receive(&mut self, frame: Frame) -> Result<ProtocolEvent, ProtocolError>

Applies an incoming frame and returns its semantic protocol event.

Source

pub fn reset_connection(&mut self) -> Vec<ProtocolEvent>

Marks active channels disconnected and returns interrupted requests.

Trait Implementations§

Source§

impl Debug for Protocol

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Protocol

Source§

fn default() -> Protocol

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.

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 = 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.