Hello all,

I’m having some trouble when using external crates in a module. For example the 
following code won’t compile.
But if I put everything in main.rs it will compile.
(Note: the code is also here https://gist.github.com/ollie/90e266f4cbfcad21501d 
if it gets mangled along the way.)

main.rs:

use lib::decode_json_file;

mod lib;

fn main() {
    decode_json_file();
}


lib.rs:

extern crate serialize;

use self::serialize::json;
// This has no effect:
// use self::serialize::{Decodable, Decoder};

#[deriving(Show, Decodable)]
struct Foo {
    foo: u8,
}

pub fn decode_json_file() {
    let raw_json = "{ \"foo\": 1 }";

    let foo: Foo = json::decode(raw_json).unwrap();

    println!("{}", foo);
}


When I run rustc main.rs, it prints this:

lib.rs:7:18: 7:27 error: failed to resolve. Did you mean `self::serialize`?
lib.rs:7 #[deriving(Show, Decodable)]
                          ^~~~~~~~~
note: in expansion of #[deriving]
lib.rs:7:1: 7:29 note: expansion site
lib.rs:7:18: 7:27 error: attempt to bound type parameter with a nonexistent 
trait `serialize::Decoder`
lib.rs:7 #[deriving(Show, Decodable)]
                          ^~~~~~~~~
note: in expansion of #[deriving]
lib.rs:7:1: 7:29 note: expansion site
lib.rs:7:18: 7:27 error: failed to resolve. Did you mean `self::serialize`?
lib.rs:7 #[deriving(Show, Decodable)]
                          ^~~~~~~~~
note: in expansion of #[deriving]
lib.rs:7:1: 7:29 note: expansion site
lib.rs:7:18: 7:27 error: attempt to implement a nonexistent trait 
`serialize::Decodable`
lib.rs:7 #[deriving(Show, Decodable)]
                          ^~~~~~~~~
note: in expansion of #[deriving]
lib.rs:7:1: 7:29 note: expansion site
lib.rs:7:18: 7:27 error: failed to resolve. Did you mean 
`self::serialize::Decodable`?
lib.rs:7 #[deriving(Show, Decodable)]
                          ^~~~~~~~~
note: in expansion of #[deriving]
lib.rs:7:1: 7:29 note: expansion site
lib.rs:7:18: 7:27 error: unresolved name `serialize::Decodable::decode`.
lib.rs:7 #[deriving(Show, Decodable)]
                          ^~~~~~~~~
note: in expansion of #[deriving]
lib.rs:7:1: 7:29 note: expansion site
error: aborting due to 6 previous errors


Am I doing something wrong?

Thank you and have a nice day,
Ollie
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to