← ClaudeAtlas

rust-crate-architecturelisted

Use when you add, split, merge, rename, or remove a crate in a Rust workspace, when you define or enforce dependency layers and direction rules, when you decide whether new code belongs in a new crate or an existing module, when you restructure a workspace after a layering violation or a dependency cycle between normal crates, or when you lay out modules inside a crate that grew too large. A cyclic package dependency that involves a proc-macro crate belongs to rust-macros.
po4yka/rust-skills · ★ 2 · AI & Automation · score 76
Install: claude install-skill po4yka/rust-skills
# Rust Crate Architecture This skill covers the shape of a Rust workspace: which crates exist, which crate is allowed to depend on which, and how modules are laid out inside a crate. `cargo-workflows` covers the mechanics of the manifests, profiles, and build commands. Use both together. ## Establish ground truth first A workspace changes faster than its documentation. Before you move any crate, read the current graph from cargo, not from a diagram. ```bash # Authoritative machine-readable inventory of the workspace members. cargo metadata --locked --no-deps --format-version 1 # Forward dependencies of one crate: what it is allowed to know. cargo tree --locked -p <crate> -e normal # Reverse dependencies of one crate: who is allowed to know it. # Pass the crate as the value of -i, and keep --workspace, or the inverted # tree is scoped to that crate alone and shows no dependents. cargo tree --locked --workspace -i <crate> ``` Rules: - Treat any hand-written architecture document as stale until `cargo metadata` agrees with it. Fix the document in the same change that moves a crate. - Do not hardcode a crate count in documentation. Derive it from `cargo metadata`. - Run every command from the directory that holds the workspace `Cargo.toml`, or pass `--manifest-path <workspace-root>/Cargo.toml`. ## The layer model Give every crate exactly one layer. The layer says what the crate is allowed to know. Names of layers matter less than the direction between them. | Lay