Hi,
I'm wondering if "external crate" declarations from modules are
discouraged in general? Because things seem to become a bit quirky, took
me a while to grasp:
First, "use" starts at the root whereas everything else starts at the
current module. E g, imagine a "test_seri.rs" file which looks like this:
extern crate serialize;
fn test_json() {
use self::serialize::json;
let _:int = json::decode("").unwrap();
}
fn test_json2() {
let _:int = serialize::json::decode("").unwrap();
}
So, since the "serialize" crate is inserted into the test_seri
namespace, I have to do "use self::serialize::json" and not "use
serialize::json" in the example above. But still I can call
"serialize::json::decode" in the second example without using the entire
path "self::serialize::json" (or test_seri::serialize::json). This is a
bit inconsistent, but doable once you understand it.
Second, in the case of the log crate, it looks like it can only be
imported in the root crate, not in a module. For two reasons. Imagine a
"test_log.rs" file looking like this:
#![feature(phase)]
#[phase(plugin, link)] extern crate log;
fn test_log() {
error!("Yo!");
}
The first is that "#![feature(phase)]" seems to be silently ignored when
not in crate root. You'll get a somewhat confusing compiler error on the
second row: "add #![feature(phase)] to the crate attributes to enable" -
it's confusing until you get that you have added "#![feature(phase)]" to
a module, not a crate.
The second is that the log macros ("error!" etc) reference
::log::LogLocation, which assumes that the log is actually imported as
::log. Which it isn't in this case, it's test_log::log. Again a
confusing compiler error "error: failed to resolve. Maybe a missing
`extern crate log`?".
(Side note: the macros are also broken if you do stuff such as 'extern
crate "log" as foo'.)
// David
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev