Why is `sin` a method?

The real usage of extern crate in the root of crate seems to define global items, so

  • extern crate a as b can give the crate a an alias b, and both a and b can be used to reference the same crate
    • so extern crate a as b acts like use a as b, but globally, which means
extern crate a as b;
use a as c;

mod m {
    // crate a and its alias b can be used in the submod, but alias c can't
}
  • extern crate self as alias can give the current crate a global alias. This is useful to unify the paths based on your crate name in macros, because you can't specify your crate name in your own crate without it, and an example for this.
    • use self as alias won't work and cause the error
error[E0429]: `self` imports are only allowed within a { } list
 --> src/main.rs:3:5
  |
3 | use self as alias;
  |     ^^^^
  • #[macro_use] extern crate a can gobally import all the macros including both decl and proc macros in the root of crate a to your crate, and submods can use them directly.
3 Likes