Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::sync::mpsc::{channel, Sender, SendError};
- #[derive(Debug)]
- pub enum EasyWsError {
- Unknown,
- }
- impl From<SendError<EasyWsCommand>> for EasyWsError {
- fn from(_e: SendError<EasyWsCommand>) -> Self {
- EasyWsError::Unknown
- }
- }
- pub enum EasyWsCommand {
- Disconnect,
- Send(String),
- }
- pub type EasyWsResult = Result<(), EasyWsError>;
- fn send<S>(tx: &Sender<EasyWsCommand>, message: S) -> EasyWsResult
- where
- S: AsRef<str>,
- {
- let msg = message.as_ref().to_string();
- tx.send(EasyWsCommand::Send(msg))?
- // Ok(())
- }
- fn main() {
- let (tx, _) = channel();
- send(&tx, "lol").unwrap();
- }
Add Comment
Please, Sign In to add comment