I'm fooling around with the ipc-channel crate, trying to build a generic struct that holds an IpcOneShotServer
:
extern crate ipc_channel;
extern crate serde;
use ipc_channel::{ipc, Error};
use serde::{Deserialize, Serialize};
struct Supervisor<T> {
server: ipc::IpcOneShotServer<T>,
}
impl<T> Supervisor<T>
where
T: for<'de> Deserialize<'de> + Serialize,
{
fn new() -> Result<Supervisor<T>, Error> {
let (server, _) = ipc::IpcOneShotServer::new()?;
Ok(Supervisor { server: server })
}
}
fn main() {}
When I try to compile this code, I get the following errors
error[E0277]: the trait bound `for<'de> T: serde::de::Deserialize<'de>` is not satisfied
--> src/main.rs:67:27
|
67 | let (server, _) = ipc::IpcOneShotServer::new()?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'de> serde::de::Deserialize<'de>` is not implemented for `T`
|
= help: consider adding a `where for<'de> T: serde::de::Deserialize<'de>` bound
= note: required by `<ipc_channel::ipc::IpcOneShotServer<T>>::new`
error[E0277]: the trait bound `T: serde::ser::Serialize` is not satisfied
--> src/main.rs:67:27
|
67 | let (server, _) = ipc::IpcOneShotServer::new()?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `serde::ser::Serialize` is not implemented for `T`
|
= help: consider adding a `where T: serde::ser::Serialize` bound
= note: required by `<ipc_channel::ipc::IpcOneShotServer<T>>::new`
I'm not sure what I'm missing here. I have bounded the trait T
by both Deserialize
and Serialize
. I thought that by binding the trait in the impl by those two other traits this would tell the type checker that as long as a Supervisor
of type T
implements Deserialize
and Serialize
it's safe to call ipc::IpcOneShotServer::new()
.