-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1369 from xiaochuanyu/extern-crate
Update extern crate related sections
- Loading branch information
Showing
6 changed files
with
31 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Library | ||
# Creating a Library | ||
|
||
Let's create a library, and then see how to link it to another crate. | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Using a Library | ||
|
||
To link a crate to this new library you may use `rustc`'s `--extern` flag. All | ||
of its items will then be imported under a module named the same as the library. | ||
This module generally behaves the same way as any other module. | ||
|
||
```rust,ignore | ||
// 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(); | ||
} | ||
``` | ||
|
||
```txt | ||
# 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 --edition=2018 && ./executable | ||
called rary's `public_function()` | ||
called rary's `indirect_access()`, that | ||
> called rary's `private_function()` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters