ライブラリの利用

クレートをこの新しいライブラリにリンクするには、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()`