From: Ralf Jung Date: Thu, 16 Jul 2015 20:29:52 +0000 (+0200) Subject: turns out that one *can* use 'extern crate' in submodules X-Git-Url: https://git.ralfj.de/rust-101.git/commitdiff_plain/98dafe0138b8bf6584b8d9e86a74a580bb034a26?ds=inline;hp=--cc turns out that one *can* use 'extern crate' in submodules --- 98dafe0138b8bf6584b8d9e86a74a580bb034a26 diff --git a/Cargo.lock b/Cargo.lock index 67ade17..b44a287 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,63 +1,4 @@ [root] name = "rust-101" version = "0.1.0" -dependencies = [ - "docopt 0.6.67 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "aho-corasick" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "docopt" -version = "0.6.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "regex 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "libc" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "memchr" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex-syntax" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rustc-serialize" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "strsim" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml index e590353..bbc666b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,5 +3,5 @@ name = "rust-101" version = "0.1.0" authors = ["Ralf Jung "] -[dependencies] -docopt = "*" +#[dependencies] +#docopt = "*" diff --git a/src/main.rs b/src/main.rs index 901e70d..4290e1e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,7 +87,6 @@ // * (to be continued) // #![allow(dead_code, unused_imports, unused_variables, unused_mut, unreachable_code)] -/* extern crate docopt; */ mod part00; mod part01; mod part02; diff --git a/src/part13.rs b/src/part13.rs index d6483d4..29647ea 100644 --- a/src/part13.rs +++ b/src/part13.rs @@ -87,13 +87,13 @@ fn sort_array() { //@ Note that crates.io is only the default location for dependencies, you can also give it the URL of a git repository or some local //@ path. All of this is explained in the [Cargo Guide](http://doc.crates.io/guide.html). -// I disabled the following module (using a rather bad hack), because it only compiles if `docopt` is linked. However, before enabling it, -// you still have get the external library into the global namespace. This is done with `extern crate docopt`, and that statement *has* to be -// in `main.rs`. So please go there, and enable this commented-out line. Then remove the attribute of the `rgrep` module. +// I disabled the following module (using a rather bad hack), because it only compiles if `docopt` is linked. +// Remove the attribute of the `rgrep` module to enable compilation. #[cfg(feature = "disabled")] pub mod rgrep { - // Now that `docopt` is linked and declared in `main.rs`, we can import it with `use`. We also import some other pieces that we will need. - use docopt::Docopt; + // Now that `docopt` is linked, we can first root it in the namespace and then import it with `use`. We also import some other pieces that we will need. + extern crate docopt; + use self::docopt::Docopt; use part12::{run, Options, OutputMode}; use std::process; diff --git a/workspace/src/part13.rs b/workspace/src/part13.rs index 88d1ea6..2be4353 100644 --- a/workspace/src/part13.rs +++ b/workspace/src/part13.rs @@ -45,13 +45,13 @@ fn sort_array() { // ## External Dependencies -// I disabled the following module (using a rather bad hack), because it only compiles if `docopt` is linked. However, before enabling it, -// you still have get the external library into the global namespace. This is done with `extern crate docopt`, and that statement *has* to be -// in `main.rs`. So please go there, and enable this commented-out line. Then remove the attribute of the `rgrep` module. +// I disabled the following module (using a rather bad hack), because it only compiles if `docopt` is linked. +// Remove the attribute of the `rgrep` module to enable compilation. #[cfg(feature = "disabled")] pub mod rgrep { - // Now that `docopt` is linked and declared in `main.rs`, we can import it with `use`. We also import some other pieces that we will need. - use docopt::Docopt; + // Now that `docopt` is linked, we can first root it in the namespace and then import it with `use`. We also import some other pieces that we will need. + extern crate docopt; + use self::docopt::Docopt; use part12::{run, Options, OutputMode}; use std::process;