Struct Server

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

An SSE server.

Implementations§

Source§

impl Server

Source

pub fn new() -> Self

Create a new server with no clients.

Source

pub fn add_client(&mut self, client: Sender)

Add a client to a server. Sender can be obtained by calling Body::channel().

Source

pub async fn send_to_clients<B: Into<Bytes>>(&mut self, text: B) -> usize

Send some text to the clients. Most often, this text is made using an EventBuilder. This will automatically remove all disconnected clients.

This function returns the number of currently connected clients.

Source

pub async fn send_heartbeat(&mut self) -> usize

Send a heartbeat (empty SSE) to all clients. This does not perform any action, but will prevent your connection being timed out for lasting too long without any data being sent.

This function returns the number of currently connected clients.

Source

pub fn disconnect_all(&mut self)

Disconnect all clients that are currently connected to the server.

Source

pub fn connections(&self) -> usize

Count the number of currently held connections.

Note that this may be an over-estimate of the number of currently connected clients, as some clients may have disconnected since the last send_to_clients or send_heartbeat (both of which prune the list of connections to those which still have a connected client).

Trait Implementations§

Source§

impl Debug for Server

Source§

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

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

impl Default for Server

Source§

fn default() -> Server

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

Auto Trait Implementations§

§

impl Freeze for Server

§

impl !RefUnwindSafe for Server

§

impl Send for Server

§

impl Sync for Server

§

impl Unpin for Server

§

impl !UnwindSafe for Server

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.