我正在玩弄ipc-channel板条箱,试图构建一个包含以下内容的通用结构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() {}
当我尝试编译此代码时,出现以下错误
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`
我不确定我在这里缺少什么。我已经T
用Deserialize
和限制了这个特征Serialize
。我认为通过将 impl 中的特征与其他两个特征绑定在一起,这将告诉类型检查器,只要 a Supervisor
of 类型T
实现Deserialize
并且Serialize
调用ipc::IpcOneShotServer::new()
.