Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ismoilovdevml committed Nov 24, 2023
1 parent 8cb82ce commit d73b4ec
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 54 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
@@ -1,5 +1,5 @@
[package]
name = "art"
name = "rassom"
version = "0.1.0"
edition = "2021"

Expand Down
44 changes: 22 additions & 22 deletions rustbook-uz/listings/ch14-more-about-cargo/listing-14-06/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
//! # Art
//! # Rassom
//!
//! A library for modeling artistic concepts.
//! Badiiy tushunchalarni modellashtirish uchun kutubxona.

pub use self::kinds::PrimaryColor;
pub use self::kinds::SecondaryColor;
pub use self::utils::mix;
pub use self::turlar::AsosiyRang;
pub use self::turlar::IkkilamchiRang;
pub use self::yordamchi::yordamchi;

pub mod kinds {
/// The primary colors according to the RYB color model.
pub enum PrimaryColor {
Red,
Yellow,
Blue,
pub mod turlar {
/// RYB rang modeliga muvofiq asosiy ranglar.
pub enum AsosiyRang {
Qizil,
Sariq,
Kok,
}

/// The secondary colors according to the RYB color model.
pub enum SecondaryColor {
Orange,
Green,
Purple,
/// RYB rang modeliga muvofiq ikkinchi darajali ranglar.
pub enum IkkilamchiRang {
Qovoqrang,
Yashil,
Siyohrang,
}
}

pub mod utils {
use crate::kinds::*;
pub mod yordamchi {
use crate::turlar::*;

/// Combines two primary colors in equal amounts to create
/// a secondary color.
pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
SecondaryColor::Orange
/// Ikkilamchi rang yaratish uchun ikkita asosiy rangni teng
/// miqdorda birlashtiradi.
pub fn yordamchi(c1: AsosiyRang, c2: AsosiyRang) -> IkkilamchiRang {
IkkilamchiRang::Qovoqrang
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// ANCHOR: here
use art::mix;
use art::PrimaryColor;
use rassom::aralashtirish;
use rassom::AsosiyRang;

fn main() {
// --snip--
// ANCHOR_END: here
let red = PrimaryColor::Red;
let yellow = PrimaryColor::Yellow;
mix(red, yellow);
let qizil = AsosiyRang::qizil;
let sariq = AsosiyRang::Sariq;
mix(qizil, sariq);
// ANCHOR: here
}
// ANCHOR_END: here
33 changes: 9 additions & 24 deletions rustbook-uz/src/ch14-02-publishing-to-crates-io.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,40 +135,25 @@ Ichki organizationni public API’dan olib tashlash uchun biz 14-5 ro‘yxatda k

<span class="caption">Ro'yxat 14-5: Elementlarni qayta eksport qilish uchun `pub use` statementlarini qo'shish</span>

The API documentation that `cargo doc` generates for this crate will now list
and link re-exports on the front page, as shown in Figure 14-4, making the
`PrimaryColor` and `SecondaryColor` types and the `mix` function easier to find.
Ushbu crate uchun `cargo doc` yaratadigan API hujjatlari Endi 14-4-rasmda ko'rsatilganidek, re-exportlarni birinchi sahifada listga oling va bog'lang, bu `AsosiyRang` va `IkkilamchiRang` turlarini va `aralashtirish` funksiyasini topishni osonlashtiradi.

<img alt="Rendered documentation for the `art` crate with the re-exports on the front page" src="img/trpl14-04.png" class="center" />
<img alt="Rendered documentation for the `art` crate with the re-exports on the front page" src="img/trpluz14.png" class="center" />

<span class="caption">Figure 14-4: The front page of the documentation for `art`
that lists the re-exports</span>
<span class="caption">14-4-rasm: re-exportlar ro'yxati keltirilgan `rassom` hujjatlarining birinchi sahifasi</span>

The `art` crate users can still see and use the internal structure from Listing
14-3 as demonstrated in Listing 14-4, or they can use the more convenient
structure in Listing 14-5, as shown in Listing 14-6:
`rassom` crate foydalanuvchilari hali ham 14-4 roʻyxatda koʻrsatilganidek, 14-3 roʻyxatdagi ichki(internal) structureni koʻrishlari va foydalanishlari mumkin yoki ular 14-6 roʻyxatda koʻrsatilganidek, 14-5 roʻyxatdagi qulayroq structuredan foydalanishlari mumkin:

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

```rust,ignore
{{#rustdoc_include ../listings/ch14-more-about-cargo/listing-14-06/src/main.rs:here}}
```

<span class="caption">Listing 14-6: A program using the re-exported items from
the `art` crate</span>

In cases where there are many nested modules, re-exporting the types at the top
level with `pub use` can make a significant difference in the experience of
people who use the crate. Another common use of `pub use` is to re-export
definitions of a dependency in the current crate to make that crate's
definitions part of your crate’s public API.

Creating a useful public API structure is more of an art than a science, and
you can iterate to find the API that works best for your users. Choosing `pub
use` gives you flexibility in how you structure your crate internally and
decouples that internal structure from what you present to your users. Look at
some of the code of crates you’ve installed to see if their internal structure
differs from their public API.
<span class="caption">Ro'yxat 14-6: `rassom` cratesidan re-export(qayta eksport) qilingan itemlarni ishlatadigan dastur</span>

Ko'plab ichki modullar mavjud bo'lsa, `pub use` bilan top leveldagi turlarni qayta eksport(re-export) qilish cratedan foydalanadigan foydalanuvchilar tajribasida sezilarli o'zgarishlarga olib kelishi mumkin. `pub use` ning yana bir keng tarqalgan qoʻllanilishi bu crate deifinationlarini cratengizning public API qismiga aylantirish uchun joriy cratedagi dependency definitionlarini qayta eksport qilishdir.

Foydali public API stucturesini yaratish fandan ko'ra ko'proq san'atdir va siz foydalanuvchilaringiz uchun eng mos keladigan APIni topish uchun takrorlashingiz mumkin. `pub use` ni tanlash sizga cratengizni ichki stuctureda moslashuvchanlikni beradi va bu ichki stuctureni foydalanuvchilarga taqdim etgan narsadan ajratadi. O'rnatgan ba'zi cratelar kodlarini ko'rib chiqing, ularning ichki tuzilishi(internal structure) public APIdan farq qiladimi yoki yo'qmi.

### Setting Up a Crates.io Account

Expand Down
Binary file added rustbook-uz/src/img/trlpuz14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d73b4ec

Please sign in to comment.