0Pricing
Learn Rust Coding · Lektion

Cargo.toml

Manifest und Abhängigkeiten

Cargo.toml ist eine kostenlose Learn Rust Coding-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Learn Rust Coding-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Learn Rust Coding-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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

Häufig gestellte Fragen

Ist die Lektion „Cargo.toml“ kostenlos?

Ja — der vollständige Text von „Cargo.toml“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Learn Rust Coding-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Learn Rust Coding-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Cargo.toml“?

Manifest und Abhängigkeiten Du übst Learn Rust Coding mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Learn Rust Coding zu starten?

Keine Vorkenntnisse erforderlich. Learn Rust Coding auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.

Wie lange dauert die Lektion „Cargo.toml“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Learn Rust Coding-Lektion Code schreiben und ausführen?

Ja. Jede Learn Rust Coding-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Cargo-Grundlagen
  2. Cargo.toml
  3. Workspaces
  4. Features und Profile
← Zurück zu Learn Rust Coding