Skip to content

Instantly share code, notes, and snippets.

@ekse
Created January 31, 2018 19:25
Show Gist options
  • Save ekse/ceee2fdbd673369ef14a327154f81538 to your computer and use it in GitHub Desktop.
Save ekse/ceee2fdbd673369ef14a327154f81538 to your computer and use it in GitHub Desktop.
extern crate ws;
use ws::{WebSocket, Sender, Handler, Factory, Message};
fn gimme_websocket() -> WebSocket<Factory<Handler = FnMut(Sender) -> (Fn(Message) -> ws::Result<()>)>> {
let f = |output: Sender| {
// The closure handler needs to take ownership of output
let handler = move |msg| {
println!("got '{}' ", msg);
};
// We must return the handler
handler
};
let ws = WebSocket::new(f);
ws
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment