pub struct WsClient {
pub url: String,
pub state: WsState,
pub auto_reconnect: bool,
pub max_reconnects: u32,
pub ping_interval: Duration,
pub pong_timeout: Duration,
pub max_queue_size: usize,
/* private fields */
}Expand description
WebSocket client driven by tick().
Fields§
§url: String§state: WsState§auto_reconnect: boolAuto-reconnect on unexpected disconnect.
max_reconnects: u32Max reconnect attempts before giving up (0 = unlimited).
ping_interval: DurationKeepalive ping interval.
pong_timeout: DurationClose connection if no pong received within this time.
max_queue_size: usizeMax size of outbound queue.
Implementations§
Source§impl WsClient
impl WsClient
pub fn new(url: impl Into<String>) -> Self
Sourcepub fn disconnect(&mut self)
pub fn disconnect(&mut self)
Disconnect but allow auto-reconnect.
Sourcepub fn send(&mut self, message: WsMessage) -> bool
pub fn send(&mut self, message: WsMessage) -> bool
Send a message. Queued if not currently connected.
Sourcepub fn send_on_channel(&mut self, channel: &str, message: WsMessage) -> bool
pub fn send_on_channel(&mut self, channel: &str, message: WsMessage) -> bool
Send a message on a named channel.
pub fn unsubscribe(&mut self, channel: &str)
pub fn drain_events(&mut self) -> impl Iterator<Item = WsEvent> + '_
pub fn is_connected(&self) -> bool
pub fn messages_sent(&self) -> u64
pub fn messages_received(&self) -> u64
pub fn bytes_sent(&self) -> u64
pub fn bytes_received(&self) -> u64
pub fn uptime(&self) -> Option<Duration>
pub fn pending_outbound(&self) -> usize
Auto Trait Implementations§
impl Freeze for WsClient
impl RefUnwindSafe for WsClient
impl Send for WsClient
impl Sync for WsClient
impl Unpin for WsClient
impl UnsafeUnpin for WsClient
impl UnwindSafe for WsClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.