extern crate

To link a crate to this new library, the extern crate declaration must be
used. This will not only link the library, but also import all its items under
a module named the same as the library. The visibility rules that apply to
modules also apply to libraries.

  1. // Link to `library`, import items under the `rary` module
  2. extern crate rary;
  3. fn main() {
  4. rary::public_function();
  5. // Error! `private_function` is private
  6. //rary::private_function();
  7. rary::indirect_access();
  8. }
  1. # Where library.rlib is the path to the compiled library, assumed that it's
  2. # in the same directory here:
  3. $ rustc executable.rs --extern rary=library.rlib && ./executable
  4. called rary's `public_function()`
  5. called rary's `indirect_access()`, that
  6. > called rary's `private_function()`