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

Використання бібліотеки

Для зв’язування крейта з цією новою бібліотекою ви можете використати прапорець --extern rustc. Усі її елементи тоді буде імпортовано під модулем з назвою, такою самою, як у бібліотеки. Цей модуль загалом поводиться так само, як і будь-який інший модуль.

// extern crate rary; // May be required for Rust 2015 edition or earlier

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

    // Error! `private_function` is private
    //rary::private_function();

    rary::indirect_access();
}
# Де library.rlib — це шлях до скомпільованої бібліотеки, припускаючи, що вона
# тут у тому самому каталозі:
$ rustc executable.rs --extern rary=library.rlib && ./executable
called rary's `public_function()`
called rary's `indirect_access()`, that
> called rary's `private_function()`