Guest User

Untitled

a guest
Mar 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. use std::sync::mpsc::{channel, Sender, SendError};
  2.  
  3. #[derive(Debug)]
  4. pub enum EasyWsError {
  5. Unknown,
  6. }
  7.  
  8. impl From<SendError<EasyWsCommand>> for EasyWsError {
  9. fn from(_e: SendError<EasyWsCommand>) -> Self {
  10. EasyWsError::Unknown
  11. }
  12. }
  13.  
  14. pub enum EasyWsCommand {
  15. Disconnect,
  16. Send(String),
  17. }
  18.  
  19. pub type EasyWsResult = Result<(), EasyWsError>;
  20.  
  21. fn send<S>(tx: &Sender<EasyWsCommand>, message: S) -> EasyWsResult
  22. where
  23. S: AsRef<str>,
  24. {
  25. let msg = message.as_ref().to_string();
  26. tx.send(EasyWsCommand::Send(msg))?
  27.  
  28. // Ok(())
  29. }
  30.  
  31.  
  32. fn main() {
  33. let (tx, _) = channel();
  34.  
  35. send(&tx, "lol").unwrap();
  36. }
Add Comment
Please, Sign In to add comment