diff --git a/rustbook-uz/listings/ch14-more-about-cargo/listing-14-07/qoshish/Cargo.lock b/rustbook-uz/listings/ch14-more-about-cargo/listing-14-07/qoshish/Cargo.lock index a456055c..e790922c 100644 --- a/rustbook-uz/listings/ch14-more-about-cargo/listing-14-07/qoshish/Cargo.lock +++ b/rustbook-uz/listings/ch14-more-about-cargo/listing-14-07/qoshish/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 = "bitta_qoshish" version = "0.1.0" [[package]] -name = "adder" +name = "qoshuvchi" version = "0.1.0" dependencies = [ - "add_one 0.1.0", + "bitta_qoshish 0.1.0", ] diff --git a/rustbook-uz/listings/ch14-more-about-cargo/listing-14-07/qoshish/qoshuvchi/src/main.rs b/rustbook-uz/listings/ch14-more-about-cargo/listing-14-07/qoshish/qoshuvchi/src/main.rs index af1002bd..6069c729 100644 --- a/rustbook-uz/listings/ch14-more-about-cargo/listing-14-07/qoshish/qoshuvchi/src/main.rs +++ b/rustbook-uz/listings/ch14-more-about-cargo/listing-14-07/qoshish/qoshuvchi/src/main.rs @@ -2,5 +2,5 @@ use bitta_qoshish; fn main() { let raqam = 10; - println!("Salom, Rust! {raqam} plyus bir {} ga teng!!", bitta_qoshish::bitta_qoshish(raqam)); + println!("Salom, Rust! {raqam} plyus bir {} ga teng!", bitta_qoshish::bitta_qoshish(raqam)); } diff --git a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/qoshish/Cargo.lock b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/qoshish/Cargo.lock index a456055c..e790922c 100644 --- a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/qoshish/Cargo.lock +++ b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/qoshish/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 = "bitta_qoshish" version = "0.1.0" [[package]] -name = "adder" +name = "qoshuvchi" version = "0.1.0" dependencies = [ - "add_one 0.1.0", + "bitta_qoshish 0.1.0", ] diff --git a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/qoshish/Cargo.lock b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/qoshish/Cargo.lock index bf6974b5..1f1c0d2c 100644 --- a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/qoshish/Cargo.lock +++ b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/qoshish/Cargo.lock @@ -3,17 +3,17 @@ version = 3 [[package]] -name = "add_one" +name = "bitta_qoshish" version = "0.1.0" dependencies = [ "rand", ] [[package]] -name = "adder" +name = "qoshuvchi" version = "0.1.0" dependencies = [ - "add_one", + "bitta_qoshish", ] [[package]] diff --git a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/qoshish/qoshuvchi/src/main.rs b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/qoshish/qoshuvchi/src/main.rs index 7deb7962..f42310b5 100644 --- a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/qoshish/qoshuvchi/src/main.rs +++ b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/qoshish/qoshuvchi/src/main.rs @@ -1,10 +1,10 @@ -use add_one; +use bitta_qoshish; fn main() { - let num = 10; + let raqam = 10; println!( - "Hello, world! {} plus one is {}!", - num, - add_one::add_one(num) + "Salom, Rust! {} plyus bir {} ga teng!", + raqam, + bitta_qoshish::bitta_qoshish(raqam) ); } diff --git a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml deleted file mode 100644 index 1448801d..00000000 --- a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[workspace] - -members = [ - "adder", - "add_one", -] diff --git a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add_one/src/lib.rs b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add_one/src/lib.rs deleted file mode 100644 index 40ceb128..00000000 --- a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add_one/src/lib.rs +++ /dev/null @@ -1,13 +0,0 @@ -pub fn add_one(x: i32) -> i32 { - x + 1 -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - assert_eq!(3, add_one(2)); - } -} diff --git a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/adder/Cargo.toml b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/adder/Cargo.toml deleted file mode 100644 index feb3d956..00000000 --- a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/adder/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "adder" -version = "0.1.0" -edition = "2021" - -[dependencies] - -add_one = { path = "../add_one" } diff --git a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/adder/src/main.rs b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/adder/src/main.rs deleted file mode 100644 index 7deb7962..00000000 --- a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/adder/src/main.rs +++ /dev/null @@ -1,10 +0,0 @@ -use add_one; - -fn main() { - let num = 10; - println!( - "Hello, world! {} plus one is {}!", - num, - add_one::add_one(num) - ); -} diff --git a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.lock b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/Cargo.lock similarity index 79% rename from rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.lock rename to rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/Cargo.lock index a456055c..ee9437e3 100644 --- a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.lock +++ b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/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 = "bitta_qoshish" version = "0.1.0" [[package]] name = "adder" version = "0.1.0" dependencies = [ - "add_one 0.1.0", + "bitta_qoshish 0.1.0", ] diff --git a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/Cargo.toml b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/Cargo.toml new file mode 100644 index 00000000..541300a9 --- /dev/null +++ b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] + +members = [ + "qoshuvchi", + "bitta_qoshish", +] diff --git a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add_one/Cargo.toml b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/bitta_qoshish/Cargo.toml similarity index 72% rename from rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add_one/Cargo.toml rename to rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/bitta_qoshish/Cargo.toml index 8af4ab81..a1884aee 100644 --- a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/add_one/Cargo.toml +++ b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/bitta_qoshish/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "add_one" +name = "bitta_qoshish" version = "0.1.0" edition = "2021" diff --git a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/bitta_qoshish/src/lib.rs b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/bitta_qoshish/src/lib.rs new file mode 100644 index 00000000..53bcdbab --- /dev/null +++ b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/bitta_qoshish/src/lib.rs @@ -0,0 +1,13 @@ +pub fn bitta_qoshish(x: i32) -> i32 { + x + 1 +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn ishlamoqda() { + assert_eq!(3, bitta_qoshish(2)); + } +} diff --git a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/qoshuvchi/Cargo.toml b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/qoshuvchi/Cargo.toml new file mode 100644 index 00000000..d38aceee --- /dev/null +++ b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/qoshuvchi/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "qoshuvchi" +version = "0.1.0" +edition = "2021" + +[dependencies] + +bitta_qoshish = { path = "../bitta_qoshish" } diff --git a/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/qoshuvchi/src/main.rs b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/qoshuvchi/src/main.rs new file mode 100644 index 00000000..f42310b5 --- /dev/null +++ b/rustbook-uz/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/qoshuvchi/src/main.rs @@ -0,0 +1,10 @@ +use bitta_qoshish; + +fn main() { + let raqam = 10; + println!( + "Salom, Rust! {} plyus bir {} ga teng!", + raqam, + bitta_qoshish::bitta_qoshish(raqam) + ); +} diff --git a/rustbook-uz/src/ch14-03-cargo-workspaces.md b/rustbook-uz/src/ch14-03-cargo-workspaces.md index 2ced57c4..4813e1ce 100644 --- a/rustbook-uz/src/ch14-03-cargo-workspaces.md +++ b/rustbook-uz/src/ch14-03-cargo-workspaces.md @@ -162,7 +162,7 @@ E'tibor bering, workspaceda har bir crate jildida *Cargo.lock* emas, balki top l Fayl nomi: bitta_qoshish/Cargo.toml ```toml -{{#include ../listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/bitta_qoshish/Cargo.toml:6:7}} +{{#include ../listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/qoshish/bitta_qoshish/Cargo.toml:6:7}} ``` Endi biz *bitta_qoshish/src/lib.rs* fayliga `use rand;` ni qo'shishimiz mumkin va *qoshish* jildida `cargo build`-ni ishga tushirish orqali butun workspaceni build qilish `rand` cratesini olib keladi va kompilyatsiya qiladi. Biz bitta ogohlantirish olamiz, chunki biz qamrab olgan `rand` ni nazarda tutmayapmiz: @@ -214,20 +214,17 @@ error[E0432]: unresolved import `rand` Buni tuzatish uchun `qoshuvchi` paketi uchun *Cargo.toml* faylini tahrirlang va `rand` ham unga dependency(bog'liqligini) ekanligini ko'rsating. `qoshuvchi` paketini yaratish *Cargo.lock* dagi `qoshuvchi` uchun depensiar ro'yxatiga `rand` qo'shadi, lekin `rand` ning qo'shimcha nusxalari yuklab olinmaydi. Cargo `rand` paketidan foydalangan holda workspacedagi har bir cratedagi har bir crate bir xil versiyadan foydalanishini taʼminladi, bu bizga joyni tejaydi va workspacedagi cratelar bir-biriga mos kelishini taʼminlaydi. -#### Adding a Test to a Workspace +#### Workspacega test qo'shish -For another enhancement, let’s add a test of the `bitta_qoshish::bitta_qoshish` function -within the `bitta_qoshish` crate: +Yana bir yaxshilanish uchun, keling, `bitta_qoshish` cratesidagi `bitta_qoshish::bitta_qoshish` funksiyasi testini qo'shamiz: Fayl nomi: bitta_qoshish/src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/bitta_qoshish/src/lib.rs}} +{{#rustdoc_include ../listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/qoshish/bitta_qoshish/src/lib.rs}} ``` -Now run `cargo test` in the top-level *add* directory. Running `cargo test` in -a workspace structured like this one will run the tests for all the crates in -the workspace: +Top-leveldagi *qoshish* jildida `cargo test`-ni ishga tushiring. Shunga o'xshash tuzilgan workspaceda `cargo test` ni o'tkazish workspacedagi barcha cratelar uchun testlarni o'tkazadi: