capnproto / capnpc-rust

Cap'n Proto code generation for Rust
76 stars 26 forks source link

from FromPointerBuilder issue #29

Closed sjmackenzie closed 8 years ago

sjmackenzie commented 8 years ago

Since moving over to v0.7.0 we've been getting this error.

The contract:

@0xbde554c96bf60f36;

struct MathsBoolean {
  boolean @0 :Bool;
}

Some code for a NAND logic gate:

  fn run(&mut self) -> Result<()> {
    let a = {
        let mut ip_a = try!(self.ports.recv("a"));
        let a_reader: maths_boolean::Reader = try!(ip_a.get_root());
        a_reader.get_boolean()
    };
    let b = {
        let mut ip_b = try!(self.ports.recv("b"));
        let b_reader: maths_boolean::Reader = try!(ip_b.get_root());
        b_reader.get_boolean()
    };

    let mut new_ip = IP::new();
    let mut boolean = new_ip.init_root::<maths_boolean::Builder>();
    boolean.set_boolean(if a == true && b == true {false} else {true});
    try!(self.ports.send("output", new_ip));
    Ok(())
  }

The error message:

   Compiling component v0.1.0 (file:///tmp/nix-build-maths_boolean_nand.drv-0/nand)
src/lib.rs:22:57: 22:65 error: the trait `capnp::traits::FromPointerReader<'_>` is not implemented for the type `contract_capnp::maths_boolean::Reader<'_>` [E0277]
src/lib.rs:22         let a_reader: maths_boolean::Reader = try!(ip_a.get_root());
                                                                      ^~~~~~~~
src/lib.rs:22:47: 22:68 note: in this expansion of try! (defined in <std macros>)
src/lib.rs:11:1: 37:2 note: in this expansion of component! (defined in <rustfbp macros>)
src/lib.rs:22:57: 22:65 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:27:57: 27:65 error: the trait `capnp::traits::FromPointerReader<'_>` is not implemented for the type `contract_capnp::maths_boolean::Reader<'_>` [E0277]
src/lib.rs:27         let b_reader: maths_boolean::Reader = try!(ip_b.get_root());
                                                                      ^~~~~~~~
src/lib.rs:27:47: 27:68 note: in this expansion of try! (defined in <std macros>)
src/lib.rs:11:1: 37:2 note: in this expansion of component! (defined in <rustfbp macros>)
src/lib.rs:27:57: 27:65 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:32:30: 32:39 error: the trait `capnp::traits::FromPointerBuilder<'_>` is not implemented for the type `contract_capnp::maths_boolean::Builder<'_>` [E0277]
src/lib.rs:32     let mut boolean = new_ip.init_root::<maths_boolean::Builder>();
                                           ^~~~~~~~~
src/lib.rs:11:1: 37:2 note: in this expansion of component! (defined in <rustfbp macros>)
src/lib.rs:32:30: 32:39 help: run `rustc --explain E0277` to see a detailed explanation
error: aborting due to 3 previous errors
Could not compile `component`.
dwrensha commented 8 years ago

In a newly initialized project using the code you supplied above, I was unable to reproduce the error.

Is it possible that you are linking to two separate versions of the capnp crate? One way to check this would be to look for multiple "capnp" entries in your Cargo.lock file. Make sure that your Cargo.toml updates "capnp" to "0.7", as well as "capnpc".

sjmackenzie commented 8 years ago

Yes indeed, rustfbp needs an update, not just the components! cheers!