Skip to main content

Segment

Struct Segment 

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

A handle for one segment of a channel. It holds only its id: subscriptions, listeners and the connection belong to the channel, so any number of handles for one segment share them. Obtain one with Channel::segment or Channel::default_segment.

Implementations§

Source§

impl Segment

Source

pub fn id(&self) -> &str

The segment’s id.

Source

pub fn subscribe(&self) -> Result<Subscription, CelerisError>

Registers interest in the segment’s messages. The first interest in a segment subscribes it, and it stays subscribed until every interest is cancelled; subscriptions are restored after every reconnect. The default segment is joined automatically and never subscribed or unsubscribed.

A subscription needs read access to the segment. No acknowledgement exists: a denial arrives later, as a PermissionDeniedError, through ChannelEventHandler::on_error. It fails with CelerisError::NotConnected once the channel is closing or closed.

Source

pub fn subscribe_presence(&self) -> Result<Subscription, CelerisError>

Registers interest in the segment’s presence joins and leaves. Watching presence is not membership: it delivers no messages, and the watcher is not itself announced or listed.

Source

pub fn on_message( &self, listener: impl Fn(&[u8], &MessageMetadata) + Send + Sync + 'static, ) -> Registration

Registers a listener for the segment’s deliveries. Each message id is delivered once within a bounded window (REV-01).

Source

pub fn on_presence( &self, listener: impl Fn(&PresenceEvent) + Send + Sync + 'static, ) -> Registration

Registers a listener for joins and leaves. Events arrive only while a presence subscription is held: the server sends them to presence subscribers alone (PRES-01).

Source

pub async fn publish( &self, payload: impl AsRef<[u8]>, ) -> Result<(), CelerisError>

Sends payload to the segment with a generated message id. It returns once the socket accepted the bytes. That is not receipt, delivery or durability: the protocol has no acknowledgements.

A publish needs write access and does not join the segment. To receive from the segment, your own publishes included, call subscribe.

While the channel reconnects, the publish waits in the queue and is sent after the reconnect, once the restored subscriptions have gone out. It then fails with the error that on_error reports if recovery stops in Failed, and with CelerisError::Cancelled if the channel closes.

It fails with CelerisError::NotConnected before the first connect, while connecting, and once failed or closed; with CelerisError::Backpressure when the publish queue (64 by default) is already full; and with CelerisError::DeliveryUnknown when the socket failed during the write, which is never resent. The plan’s cap counts the whole encoded command, not only the payload. A publish over it still succeeds here and is refused afterwards with a MessageSizeLimitError through on_error.

Dropping the returned future takes the publish back if the socket has not started to write it.

Source

pub async fn publish_with_message_id( &self, payload: impl AsRef<[u8]>, message_id: &str, ) -> Result<(), CelerisError>

Segment::publish with your own message id. Receivers drop a repeated id within their deduplication window, so reuse an id only to resend the same message.

Source

pub async fn presence_list( &self, page: i32, per_page: i32, ) -> Result<PresencePage, CelerisError>

One page of the segment’s presence. One query may be in flight per channel; it fails with CelerisError::OperationInProgress while another is pending, and with CelerisError::Timeout after the presence query timeout. page starts at 1, and per_page is 1 to 100.

Dropping the returned future frees the query slot.

Trait Implementations§

Source§

impl Clone for Segment

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 Debug for Segment

Source§

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

Formats the value using the given formatter. 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> 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> Same for T

Source§

type Output = T

Should always be Self
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.