使用库 - Rust By Example
Description: Rust by Example (RBE) is a collection of runnable examples that illustrate various Rust concepts and standard libraries.

## Keyboard shortcuts

Press `←` or `→` to navigate between chapters

Press `S` or `/` to search in the book

Press `?` to show this help

Press `Esc` to hide this help

# 使用库

要将 crate 链接到这个新库，可以使用 `rustc` 的 `--extern` 标志。库中的所有项目都会被导入到一个与库同名的模块下。这个模块的行为通常与其他模块相同。

    // extern crate rary; // Rust 2015 版本或更早版本可能需要此声明

    fn main() {
        rary::public_function();

        // 错误！`private_function` 是私有的
        //rary::private_function();

        rary::indirect_access();
    }

    # Where library.rlib is the path to the compiled library, assumed that it's
    # in the same directory here:
    $ rustc executable.rs --extern rary=library.rlib && ./executable
    called rary's `public_function()`
    called rary's `indirect_access()`, that
    > called rary's `private_function()`