1

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().

dtolnay
  • 9,621
  • 5
  • 41
  • 62
Bradley Nowacki
  • 261
  • 2
  • 8
  • This compile fine for me on rust 1.26.2 – Francois Mockers Jun 16 '18 at 23:07
  • Probably a duplicate of [Why is a trait not implemented for a type that clearly has it implemented?](https://stackoverflow.com/q/44437123/155423) but since we cannot reproduce the error, this is off topic as is. – Shepmaster Jun 16 '18 at 23:18

0 Answers0