Skip to content

Commit

Permalink
updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
ismoilovdevml committed Nov 25, 2023
1 parent 3e65db9 commit 7fb2765
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 69 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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)
);
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]

members = [
"qoshuvchi",
"bitta_qoshish",
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "add_one"
name = "bitta_qoshish"
version = "0.1.0"
edition = "2021"

Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "qoshuvchi"
version = "0.1.0"
edition = "2021"

[dependencies]

bitta_qoshish = { path = "../bitta_qoshish" }
Original file line number Diff line number Diff line change
@@ -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)
);
}
25 changes: 11 additions & 14 deletions rustbook-uz/src/ch14-03-cargo-workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ E'tibor bering, workspaceda har bir crate jildida *Cargo.lock* emas, balki top l
<span class="filename">Fayl nomi: bitta_qoshish/Cargo.toml</span>

```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:
Expand Down Expand Up @@ -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:

<span class="filename">Fayl nomi: bitta_qoshish/src/lib.rs</span>

```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:

<!-- manual-regeneration
cd listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add
Expand All @@ -238,17 +235,17 @@ paths properly

```console
$ cargo test
Compiling bitta_qoshish v0.1.0 (file:///projects/add/bitta_qoshish)
Compiling adder v0.1.0 (file:///projects/add/adder)
Compiling bitta_qoshish v0.1.0 (file:///projects/qoshish/bitta_qoshish)
Compiling adder v0.1.0 (file:///projects/qoshish/qoshuvchi)
Finished test [unoptimized + debuginfo] target(s) in 0.27s
Running unittests src/lib.rs (target/debug/deps/bitta_qoshish-f0253159197f7841)

running 1 test
test tests::it_works ... ok
test tests::ishlamoqda ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Running unittests src/main.rs (target/debug/deps/adder-49979ff40686fa8e)
Running unittests src/main.rs (target/debug/deps/qoshuvchi-49979ff40686fa8e)

running 0 tests

Expand All @@ -261,7 +258,7 @@ 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 `bitta_qoshish`
The first section of the output shows that the `ishlamoqda` test in the `bitta_qoshish`
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 `bitta_qoshish` crate.
Expand All @@ -282,7 +279,7 @@ $ cargo test -p bitta_qoshish
Running unittests src/lib.rs (target/debug/deps/bitta_qoshish-b3235fea9a156f74)

running 1 test
test tests::it_works ... ok
test tests::ishlamoqda ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Expand Down

0 comments on commit 7fb2765

Please sign in to comment.