Rust by Example

10.1 Library

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

pub fn public_function() {
    println!("called erty's `public_function()`");

fn private_function() {
    println!("called erty's `private_function()`");

pub fn indirect_access() {
    print!("called erty's `indirect_access()`, that\n> ");

$ rustc --crate-type=lib
$ ls lib*

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.