diff --git a/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.lock b/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.lock index 77292f6149..a456055c9d 100644 --- a/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.lock +++ b/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.lock @@ -1,13 +1,13 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "add-one" +name = "add_one" version = "0.1.0" [[package]] name = "adder" version = "0.1.0" dependencies = [ - "add-one 0.1.0", + "add_one 0.1.0", ] diff --git a/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.toml b/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.toml index d26e7cfb4d..1448801d5b 100644 --- a/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.toml @@ -2,5 +2,5 @@ members = [ "adder", - "add-one", + "add_one", ] diff --git a/listings/ch14-more-about-cargo/listing-14-07/add/add-one/Cargo.toml b/listings/ch14-more-about-cargo/listing-14-07/add/add_one/Cargo.toml similarity index 78% rename from listings/ch14-more-about-cargo/listing-14-07/add/add-one/Cargo.toml rename to listings/ch14-more-about-cargo/listing-14-07/add/add_one/Cargo.toml index ab555f504b..36f0ac1df8 100644 --- a/listings/ch14-more-about-cargo/listing-14-07/add/add-one/Cargo.toml +++ b/listings/ch14-more-about-cargo/listing-14-07/add/add_one/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "add-one" +name = "add_one" version = "0.1.0" edition = "2018" diff --git a/listings/ch14-more-about-cargo/listing-14-07/add/add-one/src/lib.rs b/listings/ch14-more-about-cargo/listing-14-07/add/add_one/src/lib.rs similarity index 100% rename from listings/ch14-more-about-cargo/listing-14-07/add/add-one/src/lib.rs rename to listings/ch14-more-about-cargo/listing-14-07/add/add_one/src/lib.rs diff --git a/listings/ch14-more-about-cargo/listing-14-07/add/adder/Cargo.toml b/listings/ch14-more-about-cargo/listing-14-07/add/adder/Cargo.toml index cae6ba5d2b..03c661f9df 100644 --- a/listings/ch14-more-about-cargo/listing-14-07/add/adder/Cargo.toml +++ b/listings/ch14-more-about-cargo/listing-14-07/add/adder/Cargo.toml @@ -5,4 +5,4 @@ edition = "2018" [dependencies] -add-one = { path = "../add-one" } +add_one = { path = "../add_one" } diff --git a/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.lock b/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.lock index 77292f6149..a456055c9d 100644 --- a/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.lock +++ b/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.lock @@ -1,13 +1,13 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "add-one" +name = "add_one" version = "0.1.0" [[package]] name = "adder" version = "0.1.0" dependencies = [ - "add-one 0.1.0", + "add_one 0.1.0", ] diff --git a/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.toml index d26e7cfb4d..1448801d5b 100644 --- a/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.toml @@ -2,5 +2,5 @@ members = [ "adder", - "add-one", + "add_one", ] diff --git a/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/add-one/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/add_one/Cargo.toml similarity index 78% rename from listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/add-one/Cargo.toml rename to listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/add_one/Cargo.toml index ab555f504b..36f0ac1df8 100644 --- a/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/add-one/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/add_one/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "add-one" +name = "add_one" version = "0.1.0" edition = "2018" diff --git a/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/add-one/src/lib.rs b/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/add_one/src/lib.rs similarity index 100% rename from listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/add-one/src/lib.rs rename to listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/add_one/src/lib.rs diff --git a/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/adder/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/adder/Cargo.toml index cae6ba5d2b..03c661f9df 100644 --- a/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/adder/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/adder/Cargo.toml @@ -5,4 +5,4 @@ edition = "2018" [dependencies] -add-one = { path = "../add-one" } +add_one = { path = "../add_one" } diff --git a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.lock b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.lock index 28663ec168..eec3a9e4b1 100644 --- a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.lock +++ b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.lock @@ -1,7 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "add-one" +name = "add_one" version = "0.1.0" dependencies = [ "rand", @@ -11,7 +11,7 @@ dependencies = [ name = "adder" version = "0.1.0" dependencies = [ - "add-one", + "add_one", ] [[package]] diff --git a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.toml index d26e7cfb4d..1448801d5b 100644 --- a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.toml @@ -2,5 +2,5 @@ members = [ "adder", - "add-one", + "add_one", ] diff --git a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add-one/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/Cargo.toml similarity index 81% rename from listings/ch14-more-about-cargo/output-only-03-use-rand/add/add-one/Cargo.toml rename to listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/Cargo.toml index 22e2a51240..77bde883e8 100644 --- a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add-one/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "add-one" +name = "add_one" version = "0.1.0" edition = "2018" diff --git a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add-one/src/lib.rs b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/src/lib.rs similarity index 100% rename from listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add-one/src/lib.rs rename to listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/src/lib.rs diff --git a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/adder/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/adder/Cargo.toml index cae6ba5d2b..03c661f9df 100644 --- a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/adder/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/adder/Cargo.toml @@ -5,4 +5,4 @@ edition = "2018" [dependencies] -add-one = { path = "../add-one" } +add_one = { path = "../add_one" } diff --git a/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.lock b/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.lock index 77292f6149..a456055c9d 100644 --- a/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.lock +++ b/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.lock @@ -1,13 +1,13 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "add-one" +name = "add_one" version = "0.1.0" [[package]] name = "adder" version = "0.1.0" dependencies = [ - "add-one 0.1.0", + "add_one 0.1.0", ] diff --git a/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml index d26e7cfb4d..1448801d5b 100644 --- a/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml @@ -2,5 +2,5 @@ members = [ "adder", - "add-one", + "add_one", ] diff --git a/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add-one/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add_one/Cargo.toml similarity index 78% rename from listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add-one/Cargo.toml rename to listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add_one/Cargo.toml index ab555f504b..36f0ac1df8 100644 --- a/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add-one/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add_one/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "add-one" +name = "add_one" version = "0.1.0" edition = "2018" diff --git a/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add-one/src/lib.rs b/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add_one/src/lib.rs similarity index 100% rename from listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add-one/src/lib.rs rename to listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add_one/src/lib.rs diff --git a/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/adder/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/adder/Cargo.toml index cae6ba5d2b..03c661f9df 100644 --- a/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/adder/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/adder/Cargo.toml @@ -5,4 +5,4 @@ edition = "2018" [dependencies] -add-one = { path = "../add-one" } +add_one = { path = "../add_one" } diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/.gitignore b/listings/ch14-more-about-cargo/output-only-02-add-one/add/.gitignore index 64904e06d9..fc0f08e734 100644 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/.gitignore +++ b/listings/ch14-more-about-cargo/output-only-02-add-one/add/.gitignore @@ -1 +1 @@ -add-one +add_one diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.lock b/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.lock index 77292f6149..a456055c9d 100644 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.lock +++ b/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.lock @@ -1,13 +1,13 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "add-one" +name = "add_one" version = "0.1.0" [[package]] name = "adder" version = "0.1.0" dependencies = [ - "add-one 0.1.0", + "add_one 0.1.0", ] diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.toml b/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.toml index d26e7cfb4d..1448801d5b 100644 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.toml @@ -2,5 +2,5 @@ members = [ "adder", - "add-one", + "add_one", ] diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add-one/Cargo.toml b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add-one/Cargo.toml deleted file mode 100644 index 4266f6641c..0000000000 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add-one/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "add-one" -version = "0.1.0" -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add-one/src/lib.rs b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add-one/src/lib.rs deleted file mode 100644 index 31e1bb209f..0000000000 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add-one/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/adder/Cargo.toml b/listings/ch14-more-about-cargo/output-only-02-add-one/add/adder/Cargo.toml index cae6ba5d2b..03c661f9df 100644 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/adder/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-02-add-one/add/adder/Cargo.toml @@ -5,4 +5,4 @@ edition = "2018" [dependencies] -add-one = { path = "../add-one" } +add_one = { path = "../add_one" } diff --git a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.lock b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.lock index 28663ec168..eec3a9e4b1 100644 --- a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.lock +++ b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.lock @@ -1,7 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "add-one" +name = "add_one" version = "0.1.0" dependencies = [ "rand", @@ -11,7 +11,7 @@ dependencies = [ name = "adder" version = "0.1.0" dependencies = [ - "add-one", + "add_one", ] [[package]] diff --git a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.toml b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.toml index d26e7cfb4d..1448801d5b 100644 --- a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.toml @@ -2,5 +2,5 @@ members = [ "adder", - "add-one", + "add_one", ] diff --git a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add-one/Cargo.toml b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/Cargo.toml similarity index 81% rename from listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add-one/Cargo.toml rename to listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/Cargo.toml index 22e2a51240..77bde883e8 100644 --- a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add-one/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "add-one" +name = "add_one" version = "0.1.0" edition = "2018" diff --git a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add-one/src/lib.rs b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/src/lib.rs similarity index 100% rename from listings/ch14-more-about-cargo/output-only-03-use-rand/add/add-one/src/lib.rs rename to listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/src/lib.rs diff --git a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/adder/Cargo.toml b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/adder/Cargo.toml index cae6ba5d2b..03c661f9df 100644 --- a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/adder/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/adder/Cargo.toml @@ -5,4 +5,4 @@ edition = "2018" [dependencies] -add-one = { path = "../add-one" } +add_one = { path = "../add_one" } diff --git a/src/ch14-03-cargo-workspaces.md b/src/ch14-03-cargo-workspaces.md index 5d8f834284..6d21877ae3 100644 --- a/src/ch14-03-cargo-workspaces.md +++ b/src/ch14-03-cargo-workspaces.md @@ -78,8 +78,8 @@ avoid unnecessary rebuilding. ### Creating the Second Package in the Workspace -Next, let’s create another member package in the workspace and call it `add-one`. -Change the top-level *Cargo.toml* to specify the *add-one* path in the +Next, let’s create another member package in the workspace and call it `add_one`. +Change the top-level *Cargo.toml* to specify the *add_one* path in the `members` list: Filename: Cargo.toml @@ -88,18 +88,18 @@ Change the top-level *Cargo.toml* to specify the *add-one* path in the {{#include ../listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.toml}} ``` -Then generate a new library crate named `add-one`: +Then generate a new library crate named `add_one`: ```console -$ cargo new add-one --lib - Created library `add-one` package +$ cargo new add_one --lib + Created library `add_one` package ``` Your *add* directory should now have these directories and files: @@ -107,7 +107,7 @@ Your *add* directory should now have these directories and files: ```text ├── Cargo.lock ├── Cargo.toml -├── add-one +├── add_one │ ├── Cargo.toml │ └── src │ └── lib.rs @@ -118,17 +118,17 @@ Your *add* directory should now have these directories and files: └── target ``` -In the *add-one/src/lib.rs* file, let’s add an `add_one` function: +In the *add_one/src/lib.rs* file, let’s add an `add_one` function: -Filename: add-one/src/lib.rs +Filename: add_one/src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/add-one/src/lib.rs}} +{{#rustdoc_include ../listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/add_one/src/lib.rs}} ``` Now that we have another package in the workspace, we can have the `adder` -package with our binary depend on the `add-one` package, that has our -library. First, we’ll need to add a path dependency on `add-one` to +package with our binary depend on the `add_one` package, that has our +library. First, we’ll need to add a path dependency on `add_one` to *adder/Cargo.toml*. Filename: adder/Cargo.toml @@ -140,9 +140,9 @@ library. First, we’ll need to add a path dependency on `add-one` to Cargo doesn’t assume that crates in a workspace will depend on each other, so we need to be explicit about the dependency relationships between the crates. -Next, let’s use the `add_one` function from the `add-one` crate in the `adder` +Next, let’s use the `add_one` function from the `add_one` crate in the `adder` crate. Open the *adder/src/main.rs* file and add a `use` line at the top to -bring the new `add-one` library crate into scope. Then change the `main` +bring the new `add_one` library crate into scope. Then change the `main` function to call the `add_one` function, as in Listing 14-7. Filename: adder/src/main.rs @@ -151,7 +151,7 @@ function to call the `add_one` function, as in Listing 14-7. {{#rustdoc_include ../listings/ch14-more-about-cargo/listing-14-07/add/adder/src/main.rs}} ``` -Listing 14-7: Using the `add-one` library crate from the +Listing 14-7: Using the `add_one` library crate from the `adder` crate Let’s build the workspace by running `cargo build` in the top-level *add* @@ -165,7 +165,7 @@ copy output below; the output updating script doesn't handle subdirectories in p ```console $ cargo build - Compiling add-one v0.1.0 (file:///projects/add/add-one) + Compiling add_one v0.1.0 (file:///projects/add/add_one) Compiling adder v0.1.0 (file:///projects/add/adder) Finished dev [unoptimized + debuginfo] target(s) in 0.68s ``` @@ -187,19 +187,19 @@ $ cargo run -p adder Hello, world! 10 plus one is 11! ``` -This runs the code in *adder/src/main.rs*, which depends on the `add-one` crate. +This runs the code in *adder/src/main.rs*, which depends on the `add_one` crate. #### Depending on an External Package in a Workspace Notice that the workspace has only one *Cargo.lock* file at the top level of the workspace rather than having a *Cargo.lock* in each crate’s directory. This ensures that all crates are using the same version of all dependencies. If we -add the `rand` package to the *adder/Cargo.toml* and *add-one/Cargo.toml* +add the `rand` package to the *adder/Cargo.toml* and *add_one/Cargo.toml* files, Cargo will resolve both of those to one version of `rand` and record that in the one *Cargo.lock*. Making all crates in the workspace use the same dependencies means the crates in the workspace will always be compatible with each other. Let’s add the `rand` crate to the `[dependencies]` section in the -*add-one/Cargo.toml* file to be able to use the `rand` crate in the `add-one` +*add_one/Cargo.toml* file to be able to use the `rand` crate in the `add_one` crate: -Filename: add-one/Cargo.toml +Filename: add_one/Cargo.toml ```toml -{{#include ../listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add-one/Cargo.toml:7:8}} +{{#include ../listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/Cargo.toml:7:8}} ``` -We can now add `use rand;` to the *add-one/src/lib.rs* file, and building the +We can now add `use rand;` to the *add_one/src/lib.rs* file, and building the whole workspace by running `cargo build` in the *add* directory will bring in and compile the `rand` crate. We will get one warning because we aren’t referring to the `rand` we brought into scope: @@ -231,9 +231,9 @@ $ cargo build Downloaded rand v0.8.3 --snip-- Compiling rand v0.8.3 - Compiling add-one v0.1.0 (file:///projects/add/add-one) + Compiling add_one v0.1.0 (file:///projects/add/add_one) warning: unused import: `rand` - --> add-one/src/lib.rs:1:5 + --> add_one/src/lib.rs:1:5 | 1 | use rand; | ^^^^ @@ -247,7 +247,7 @@ warning: 1 warning emitted ``` The top-level *Cargo.lock* now contains information about the dependency of -`add-one` on `rand`. However, even though `rand` is used somewhere in the +`add_one` on `rand`. However, even though `rand` is used somewhere in the workspace, we can’t use it in other crates in the workspace unless we add `rand` to their *Cargo.toml* files as well. For example, if we add `use rand;` to the *adder/src/main.rs* file for the `adder` package, we’ll get an error: @@ -283,10 +283,10 @@ in the workspace will be compatible with each other. For another enhancement, let’s add a test of the `add_one::add_one` function within the `add_one` crate: -Filename: add-one/src/lib.rs +Filename: add_one/src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add-one/src/lib.rs}} +{{#rustdoc_include ../listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add_one/src/lib.rs}} ``` Now run `cargo test` in the top-level *add* directory: @@ -299,7 +299,7 @@ copy output below; the output updating script doesn't handle subdirectories in p ```console $ cargo test - Compiling add-one v0.1.0 (file:///projects/add/add-one) + Compiling add_one v0.1.0 (file:///projects/add/add_one) Compiling adder v0.1.0 (file:///projects/add/adder) Finished test [unoptimized + debuginfo] target(s) in 0.27s Running target/debug/deps/add_one-f0253159197f7841 @@ -315,17 +315,17 @@ running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - Doc-tests add-one + Doc-tests add_one running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s ``` -The first section of the output shows that the `it_works` test in the `add-one` +The first section of the output shows that the `it_works` test in the `add_one` crate passed. The next section shows that zero tests were found in the `adder` crate, and then the last section shows zero documentation tests were found in -the `add-one` crate. Running `cargo test` in a workspace structured like this +the `add_one` crate. Running `cargo test` in a workspace structured like this one will run the tests for all the crates in the workspace. We can also run tests for one particular crate in a workspace from the @@ -334,12 +334,12 @@ we want to test: ```console -$ cargo test -p add-one +$ cargo test -p add_one Finished test [unoptimized + debuginfo] target(s) in 0.00s Running target/debug/deps/add_one-b3235fea9a156f74 @@ -348,14 +348,14 @@ test tests::it_works ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - Doc-tests add-one + Doc-tests add_one running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s ``` -This output shows `cargo test` only ran the tests for the `add-one` crate and +This output shows `cargo test` only ran the tests for the `add_one` crate and didn’t run the `adder` crate tests. If you publish the crates in the workspace to [crates.io](https://crates.io/), @@ -365,7 +365,7 @@ change to each crate’s directory and run `cargo publish` on each crate in the workspace to publish the crates. For additional practice, add an `add-two` crate to this workspace in a similar -way as the `add-one` crate! +way as the `add_one` crate! As your project grows, consider using a workspace: it’s easier to understand smaller, individual components than one big blob of code. Furthermore, keeping