مساحات العمل
مشاريع متعددة الـCrates
مساحات العمل درس مجاني في Learn Rust Coding على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Learn Rust Coding، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Learn Rust Coding 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
What Is a Workspace?
A workspace is a set of related crates that share a single Cargo.lock and a common target directory. It's the standard way to manage multi-crate projects.
The Root Manifest
The workspace root has a Cargo.toml with a [workspace] table listing the member crates. The root itself usually has no package.
[workspace]
members = ["app", "core", "utils"]
resolver = "2"Workspace Layout
A typical layout puts each crate in its own subdirectory:
Cargo.toml— workspace rootapp/— a binary cratecore/— a library crateutils/— another library crate
Creating Members
You create members like any crate, then add them to the root manifest's members list.
cargo new app
cargo new core --lib
cargo new utils --libDepending on a Member
One member crate depends on another using a path dependency in its own Cargo.toml.
[dependencies]
core = { path = "../core" }
utils = { path = "../utils" }Calling Across Crates
Public items in one crate are used from another by referencing the crate name. Here core exposes a function the binary calls.
// in core/src/lib.rs
pub fn greeting(name: &str) -> String {
format!("Hello, {name}!")
}
// in app/src/main.rs
fn main() {
let msg = core::greeting("workspace");
println!("{msg}");
}Building the Whole Workspace
Running Cargo at the root builds every member. The shared target directory means common dependencies are compiled only once.
cargo build
cargo testTargeting One Member
Use -p (or --package) to run a command for a single member crate.
cargo run -p app
cargo test -p coreWorkspace Dependencies
Define shared versions once under [workspace.dependencies], then reference them from members to keep versions in sync.
# root Cargo.toml
[workspace.dependencies]
serde = "1.0"
# member Cargo.toml
[dependencies]
serde = { workspace = true }Why Use Workspaces?
Benefits of a workspace:
- Single shared lockfile for consistent versions
- Faster builds via one shared target directory
- Easy to split a large project into focused crates
- One command builds and tests everything
Excluding a Directory
The exclude key keeps certain directories out of the workspace, while default-members sets which crates run when you do not pass -p.
[workspace]
members = ["app", "core"]
exclude = ["experiments"]
default-members = ["app"]Quick Check
What do all crates in a workspace share?
Recap
You learned about workspaces:
- The
[workspace]table lists members - Members depend on each other via
path - A shared lockfile and target directory speed up builds
- Use
-pto target one member [workspace.dependencies]centralizes versions
الأسئلة الشائعة
هل درس «مساحات العمل» مجاني؟
نعم — نص درس «مساحات العمل» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Learn Rust Coding، انتقل إلى CoddyKit PRO. تتضمن دورة Learn Rust Coding 4 دروس في المجموع.
ماذا ستتعلم في «مساحات العمل»؟
مشاريع متعددة الـCrates تتمرن على Learn Rust Coding مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Learn Rust Coding؟
لا تُشترط خبرة سابقة. Learn Rust Coding على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «مساحات العمل»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Learn Rust Coding هذا؟
نعم. كل درس في Learn Rust Coding يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.