라이브러리 사용
이 새로운 라이브러리에 크레이트를 연결하려면 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()`