Library

Let’s create a library, and then see how to link it to another crate.

  1. pub fn public_function() {
  2. println!("called rary's `public_function()`");
  3. }
  4. fn private_function() {
  5. println!("called rary's `private_function()`");
  6. }
  7. pub fn indirect_access() {
  8. print!("called rary's `indirect_access()`, that\n> ");
  9. private_function();
  10. }
  1. $ rustc --crate-type=lib rary.rs
  2. $ ls lib*
  3. library.rlib

Libraries get prefixed with “lib”, and by default they get named after their
crate file, but this default name can be overridden using the crate_name
attribute
.