Hi, I'm trying to write a generic websocket server and the messages will be generic enums. One of the enum variants will wrap a user provided type as follows:
#[derive(Deserialize, Serialize, Debug)]
enum MessageToServer<T>
where
T: Debug,
{
Connect,
Data(T),
Disconnect,
Invalid,
Unsupported,
}
#[derive(Deserialize, Serialize, Debug)]
enum MessageFromServer<T>
where
T: Debug,
{
Data(T),
Invalid,
Connect,
Disconnect,
}
The problem I'm having is that now all the functions that start the server need to be generic on type T. Additionally the "Deserialize" trait requires a lifetime bound and I get the following error
error[E0310]: the parameter type `T` may not live long enough
--> realtime/src/websocket_server/connection_handler.rs:68:5
|
68 | websocket.on_upgrade(move |socket| handle_socket::<T>(socket, addr))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
I've tried setting explicit lifetime bounds for each of these functions but it doesn't seem to fix the issue. Could I get some guidance? From my brief research I see that 'static should not be used in combination with the Deserialize trait.

