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 يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. أساسيات Cargo
  2. Cargo.toml
  3. مساحات العمل
  4. الميزات والملفات التعريفية
← العودة إلى Learn Rust Coding