I'm trying to create a helper function to assist in creating a WebSocket struct from the ws crate and I'd like to return this constructed WebSocket struct but I can't for the life of me figure this out. I've gone down the rabbit hole of everything suggested by the compiler without success.
pub fn create_server<F>(bind_addr: String, ssl_certs: &SSLCert) -> WebSocket<F>
{
let web_socket = ws::Builder::new()
.with_settings(
ws::Settings {
queue_size: 100,
encrypt_server: true,
tcp_nodelay: true,
..ws::Settings::default()
}
)
.build(|out: ws::Sender| WSServer {
out: out,
ssl: ssl_certs.acceptor(SSLConfiguration::Modern).unwrap(),
})
.unwrap();
web_socket
}
struct WSServer {
out: ws::Sender,
ssl: Rc<SslAcceptor>,
}
Error Message:
error[E0277]: expected a `FnMut<(ws::Sender,)>` closure, found `F`
--> src\server.rs:102:68
|
102 | pub fn create_server<F>(bind_addr: String, ssl_certs: &SSLCert) -> WebSocket<F>
| ^^^^^^^^^^^^ expected an `FnMut<(ws::Sender,)>` closure, found `F`
|
= note: required because of the requirements on the impl of `Factory` for `F`
note: required by a bound in `WebSocket`
--> C:\Users\...\.cargo\registry\src\github.com-1ecc6299db9ec823\ws-0.9.2\src\lib.rs:276:8
|
276 | F: Factory,
| ^^^^^^^ required by this bound in `WebSocket`
help: consider restricting type parameter `F`
|
102 | pub fn create_server<F: std::ops::FnMut<(ws::Sender,)>>(bind_addr: String, ssl_certs: &SSLCert) -> WebSocket<F>
| ++++++++++++++++++++++++++++++++
For more information about this error, try `rustc --explain E0277`.