Struct ws_tool::codec::StringCodec
source · pub struct StringCodec<S: Read + Write> { /* private fields */ }Expand description
recv/send text message
Implementations§
source§impl<S: Read + Write> StringCodec<S>
impl<S: Read + Write> StringCodec<S>
sourcepub fn new_with(stream: S, config: FrameConfig, validate_utf8: bool) -> Self
pub fn new_with(stream: S, config: FrameConfig, validate_utf8: bool) -> Self
construct with config
sourcepub fn stream_mut(&mut self) -> &mut S
pub fn stream_mut(&mut self) -> &mut S
get mutable underlying stream
sourcepub fn factory(_req: Request<()>, stream: S) -> Result<Self, WsError>
pub fn factory(_req: Request<()>, stream: S) -> Result<Self, WsError>
used for server side to construct a new server
sourcepub fn check_fn(
key: String,
resp: Response<()>,
stream: S
) -> Result<Self, WsError>
pub fn check_fn( key: String, resp: Response<()>, stream: S ) -> Result<Self, WsError>
used to client side to construct a new client
sourcepub fn receive_raw(&mut self) -> Result<Message<Cow<'_, [u8]>>, WsError>
pub fn receive_raw(&mut self) -> Result<Message<Cow<'_, [u8]>>, WsError>
in case of ping/pong/close contain non utf-8 string, use this api to receive raw message
for close frame with body, first two bytes of string are close reason
sourcepub fn receive(&mut self) -> Result<Message<Cow<'_, str>>, WsError>
pub fn receive(&mut self) -> Result<Message<Cow<'_, str>>, WsError>
for close frame with body, first two bytes of string are close reason
sourcepub fn ping<'a>(&mut self, msg: &'a str) -> Result<(), WsError>
pub fn ping<'a>(&mut self, msg: &'a str) -> Result<(), WsError>
helper method to send ping message
sourcepub fn pong<'a>(&mut self, msg: &'a str) -> Result<(), WsError>
pub fn pong<'a>(&mut self, msg: &'a str) -> Result<(), WsError>
helper method to send pong message
sourcepub fn close<'a>(&mut self, code: u16, msg: &'a str) -> Result<(), WsError>
pub fn close<'a>(&mut self, code: u16, msg: &'a str) -> Result<(), WsError>
helper method to send close message
source§impl<R, W, S> StringCodec<S>where
R: Read,
W: Write,
S: Read + Write + Split<R = R, W = W>,
impl<R, W, S> StringCodec<S>where R: Read, W: Write, S: Read + Write + Split<R = R, W = W>,
sourcepub fn split(self) -> (StringRecv<R>, StringSend<W>)
pub fn split(self) -> (StringRecv<R>, StringSend<W>)
split codec to recv and send parts
Auto Trait Implementations§
impl<S> RefUnwindSafe for StringCodec<S>where S: RefUnwindSafe,
impl<S> Send for StringCodec<S>where S: Send,
impl<S> Sync for StringCodec<S>where S: Sync,
impl<S> Unpin for StringCodec<S>where S: Unpin,
impl<S> UnwindSafe for StringCodec<S>where S: UnwindSafe,
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