pub enum ConnectionEvent {
Connected,
Disconnected(String),
Message(Vec<u8>),
Error(FlareError),
}Expand description
连接事件
表示连接上发生的各种事件,由 ConnectionObserver 使用以响应连接状态和数据接收。
Variants§
Connected
连接成功建立时触发
Disconnected(String)
连接关闭时触发
参数提供断开连接的原因
Message(Vec<u8>)
收到新消息时触发
负载是字节向量
Error(FlareError)
连接上发生非致命错误时触发
Implementations§
Source§impl ConnectionEvent
impl ConnectionEvent
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
检查是否为连接事件
Sourcepub fn is_disconnected(&self) -> bool
pub fn is_disconnected(&self) -> bool
检查是否为断开连接事件
Sourcepub fn is_message(&self) -> bool
pub fn is_message(&self) -> bool
检查是否为消息事件
Sourcepub fn disconnect_reason(&self) -> Option<&str>
pub fn disconnect_reason(&self) -> Option<&str>
获取断开连接的原因(如果是断开连接事件)
Sourcepub fn message_data(&self) -> Option<&[u8]>
pub fn message_data(&self) -> Option<&[u8]>
获取消息数据(如果是消息事件)
Sourcepub fn error(&self) -> Option<&FlareError>
pub fn error(&self) -> Option<&FlareError>
获取错误(如果是错误事件)
Trait Implementations§
Source§impl Clone for ConnectionEvent
impl Clone for ConnectionEvent
Source§fn clone(&self) -> ConnectionEvent
fn clone(&self) -> ConnectionEvent
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ConnectionEvent
impl RefUnwindSafe for ConnectionEvent
impl Send for ConnectionEvent
impl Sync for ConnectionEvent
impl Unpin for ConnectionEvent
impl UnsafeUnpin for ConnectionEvent
impl UnwindSafe for ConnectionEvent
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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