Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update extern crate related sections #1369

Merged
merged 4 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
- [File hierarchy](mod/split.md)

- [Crates](crates.md)
- [Library](crates/lib.md)
- [`extern crate`](crates/link.md)
- [Creating a Library](crates/lib.md)
- [Using a Library](crates/using_lib.md)

- [Cargo](cargo.md)
- [Dependencies](cargo/deps.md)
Expand Down
2 changes: 1 addition & 1 deletion src/crates/lib.md
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.

Expand Down
29 changes: 0 additions & 29 deletions src/crates/link.md

This file was deleted.

27 changes: 27 additions & 0 deletions src/crates/using_lib.md
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
Copy link
Contributor Author

@xiaochuanyu xiaochuanyu Aug 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I added --edition=2018. rustc currently still defaults to 2015 (but cargo new defaults to 2018).

called rary's `public_function()`
called rary's `indirect_access()`, that
> called rary's `private_function()`
```
2 changes: 0 additions & 2 deletions src/mod/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ The `use` declaration can be used to bind a full path to a new name, for easier
access. It is often used like this:

```rust,editable,ignore
// extern crate deeply; // normally, this would exist and not be commented out!

use crate::deeply::nested::{
my_first_function,
my_second_function,
Expand Down
8 changes: 1 addition & 7 deletions src/testing/integration_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Cargo looks for integration tests in `tests` directory next to `src`.
File `src/lib.rs`:

```rust,ignore
// Assume that crate is called adder, will have to extern it in integration test.
// Define this in a crate called `adder`.
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
Expand All @@ -19,9 +19,6 @@ pub fn add(a: i32, b: i32) -> i32 {
File with test: `tests/integration_test.rs`:

```rust,ignore
// extern crate we're testing, same as any other code would do.
extern crate adder;

#[test]
fn test_add() {
assert_eq!(adder::add(3, 2), 5);
Expand Down Expand Up @@ -66,9 +63,6 @@ pub fn setup() {
File with test: `tests/integration_test.rs`

```rust,ignore
// extern crate we're testing, same as any other code will do.
extern crate adder;

// importing common module.
mod common;

Expand Down