0Pricing
Learn Rust Coding · Урок

Cargo.toml

Манифест и зависимости

«Cargo.toml» — бесплатный урок Learn Rust Coding на CoddyKit. Это урок 2 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Learn Rust Coding, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Learn Rust Coding содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

The Manifest

Cargo.toml is the manifest file at the root of every Rust project. It describes the package and its dependencies using the TOML format.

The [package] Section

The [package] table holds metadata about your crate.

  • name — the crate name
  • version — semantic version
  • edition — the Rust edition (e.g. 2021)
[package]
name = "my_app"
version = "0.1.0"
edition = "2021"

Adding Dependencies

List external crates under [dependencies]. Cargo downloads them from crates.io and compiles them for you.

[dependencies]
rand = "0.8"
serde = "1.0"

cargo add

Instead of editing the file by hand, use cargo add to insert a dependency with the latest compatible version.

cargo add rand
cargo add serde

Version Requirements

Version strings use semver rules:

  • "1.0" means >=1.0.0 and <2.0.0 (caret by default)
  • "=1.2.3" pins an exact version
  • "~1.2" allows patch updates only
[dependencies]
regex = "=1.10.2"
log = "~0.4"

Using a Dependency

Once added, bring items into scope with use and call them in code. Here we use the rand crate (in a real project).

use rand::Rng;

fn main() {
    let mut rng = rand::thread_rng();
    let n: u8 = rng.gen_range(1..=6);
    println!("Rolled a {n}");
}

Dependency Features

Many crates expose optional features. Enable them with the features key, often disabling defaults first.

[dependencies]
serde = { version = "1.0", features = ["derive"] }

Dev Dependencies

[dev-dependencies] are only compiled for tests, examples, and benchmarks — never shipped with your library.

[dev-dependencies]
pretty_assertions = "1.4"

Path and Git Dependencies

Dependencies can also come from a local path or a git repository instead of crates.io.

[dependencies]
my_lib = { path = "../my_lib" }
some_crate = { git = "https://github.com/user/repo" }

Updating Dependencies

cargo update bumps dependencies to the newest versions allowed by your version requirements and rewrites Cargo.lock.

cargo update

Optional Package Metadata

The [package] table accepts extra fields that show up on crates.io when you publish:

  • authors — who wrote it
  • description — a short summary
  • license — an SPDX identifier like MIT
  • repository — the source URL
[package]
name = "my_app"
version = "0.1.0"
edition = "2021"
description = "A small demo crate"
license = "MIT"

Quick Check

Where should a crate that is only needed when running tests be listed?

Recap

You explored the manifest:

  • [package] holds metadata like name, version, edition
  • [dependencies] declares crates from crates.io, path, or git
  • Version strings follow semver rules
  • features enable optional functionality
  • [dev-dependencies] are test-only

Часто задаваемые вопросы

Урок «Cargo.toml» бесплатный?

Да — полный текст урока «Cargo.toml» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Learn Rust Coding, подпишись на CoddyKit PRO. Курс Learn Rust Coding содержит 4 уроков всего.

Чему я научусь в уроке «Cargo.toml»?

Манифест и зависимости Ты практикуешь Learn Rust Coding с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Learn Rust Coding?

Предыдущий опыт не требуется. Learn Rust Coding на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 2 из 4.

Сколько времени занимает урок «Cargo.toml»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке Learn Rust Coding?

Да. Каждый урок Learn Rust Coding включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Основы Cargo
  2. Cargo.toml
  3. Рабочие пространства
  4. Возможности и профили
← Назад к Learn Rust Coding