بنقرة واحدة
rust-crate-architecture
Rust crate creation, workspace restructuring, dependency layering, and direction rules.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Rust crate creation, workspace restructuring, dependency layering, and direction rules.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Use this skill to generate well-branded interfaces and assets for RIPDPI (an Android-native, Compose-first VPN and DPI-bypass app), either for production or throwaway prototypes/mocks/etc. Contains essential design guidelines, colors, type, fonts, brand-ship icons, and an interactive UI kit of every public composable from the live ui/components tree.
Use when managing the Rust workspace, adding/removing crates, editing workspace dependencies, running cargo nextest/audit/deny, configuring Cargo profiles for Android cross-compilation, debugging Cargo.lock churn, migrating crate edition, or wiring Gradle to cargo via the ripdpi.android.rust-native plugin.
Use when modifying the diagnostics scan pipeline, ScanRequest/ScanReport types, ProbeTask families, ripdpi-monitor-engine / ripdpi-diagnostics-* crates, strategy-probe candidates, the diagnostics catalog (packs/profiles), wire-schema contracts between Rust and Kotlin, DIAGNOSTICS_ENGINE_SCHEMA_VERSION, golden contract tests, or adding a new probe type / profile. Triggers on diagnostics scans, strategy probes, automatic audit, dpi-detector profiles, or anything in core/diagnostics or native/rust/crates/ripdpi-monitor-*.
Android-specific Rust build, verification, and packaging — per-target 16 KiB page alignment, size-optimized release profile, ELF symbol allowlist, .so size budgets, NDK 29 specifics. Use when modifying .cargo/config.toml for Android targets, the workspace [profile.release] / [profile.android-jni] block, or when verifying a built .so before release.
Telemetry and observability discipline for the RIPDPI Android Rust stack — control-plane vs data-plane logging, bounded flume event queues, atomic counters, snapshot polling, readiness callbacks, and deterministic JSON contracts. Use when authoring or modifying telemetry emission code, the bounded event ring, the Kotlin-side telemetry consumer, or any per-packet logging.
Custom detekt rules, DI/privacy/suppression guardrails, detekt.yml configuration, and false-positive triage.
| name | rust-crate-architecture |
| description | Rust crate creation, workspace restructuring, dependency layering, and direction rules. |
The native/rust/ workspace is large and changes frequently. Treat native/rust/Cargo.toml, cargo metadata --locked, and docs/architecture/NATIVE_RUST.md as the current crate inventory. Dependencies should still flow toward smaller/shared crates and away from Android/JNI adapter crates.
docs/architecture/NATIVE_RUST.md is the maintained crate taxonomy and native artifact map.cargo metadata --locked --manifest-path native/rust/Cargo.toml --no-deps is the authoritative machine-readable workspace inventory.ripdpi-android, ripdpi-tunnel-android, ripdpi-warp-android, ripdpi-relay-android) should stay as adapters over domain/runtime crates.ripdpi-monitor-engine, ripdpi-diagnostics-runner, ripdpi-diagnostics-contracts, and per-protocol ripdpi-diagnostics-* crates.ripdpi-proxy-runtime and its adapter/service crates, not under removed legacy crate names.| Crate | Purpose |
|---|---|
golden-test-support | Golden file test infrastructure |
local-network-fixture | Local DNS/HTTP/TCP server fixtures |
native-soak-support | Soak/stress test harness |
android-support | Android logging + JNI helpers (also runtime dep for android crates) |
Layer N crates must not depend on Layer N+1 crates. Cargo enforces no cycles, but upward deps within the same cycle-free graph are still architecturally wrong.
Example violations:
ripdpi-config depending on ripdpi-proxy-runtimeripdpi-packets depending on ripdpi-desync (Layer 0 -> Layer 1)The workspace has two independent dependency trees:
Proxy stack: ripdpi-packets -> ripdpi-config -> ripdpi-desync -> ripdpi-proxy-runtime -> ripdpi-android
Tunnel stack: ripdpi-tun-driver -> ripdpi-tunnel-config -> ripdpi-tunnel-core -> ripdpi-tunnel-android
These stacks share only foundation crates such as ripdpi-packets and ripdpi-failure-classifier. Do not introduce cross-stack dependencies (e.g., ripdpi-tunnel-core must not depend on ripdpi-proxy-runtime).
golden-test-support, local-network-fixture, and native-soak-support must appear under [dev-dependencies] only. Exception: android-support is also a runtime dependency for ripdpi-android and ripdpi-tunnel-android.
ripdpi-monitor-engine may use diagnostics runner/protocol crates and shared runtime contracts, but proxy/tunnel runtime crates must not depend back on ripdpi-monitor-engine. Keep diagnostics observation as an adapter edge, not a core runtime dependency.
Platform-specific code lives behind #[cfg(target_os = "...")] gates, never creating conditional dependencies that break the layer model.
Choose layer: determine which layers the new crate needs to depend on. Place it at the minimum layer that satisfies its dependencies.
Create directory:
cd native/rust
cargo init --lib crates/<crate-name>
Add to workspace in native/rust/Cargo.toml:
# [workspace] members list
members = [
# ... existing members
"crates/<crate-name>",
]
# [workspace.dependencies] section
<crate-name> = { path = "crates/<crate-name>" }
Configure crate Cargo.toml:
[package]
name = "<crate-name>"
edition.workspace = true
version.workspace = true
license.workspace = true
[dependencies]
# Use workspace = true for all deps
ripdpi-packets = { workspace = true }
[lints]
workspace = true
Add safety attribute to lib.rs:
#![forbid(unsafe_code)]
Omit only if the crate genuinely needs unsafe (JNI crates, tun-driver).
Verify:
cargo clippy --locked -p <crate-name> --all-targets -- -D warnings
cargo deny --locked check
ripdpi- for proxy/network cratesripdpi-tunnel- for tunnel-stack cratesgolden-test-support, local-network-fixture)Single lib.rs with inline #[cfg(test)] mod tests.
src/
lib.rs # mod declarations + pub use re-exports
types.rs # data structures
logic.rs # core algorithms
Inline tests or a single tests.rs file.
src/
lib.rs # mod declarations + pub use re-exports
engine.rs # module root (declares sub-modules)
engine/
plan.rs
report.rs
runners.rs
tests.rs # focused test module
types.rs # module root
types/
request.rs
response.rs
test_fixtures.rs # shared test helpers (#[cfg(test)])
tests.rs # top-level unit tests
tests/
integration.rs # integration tests
golden/ # golden test fixtures
Use name.rs + name/ directory pattern. Use mod.rs only for 3+ level deep nesting.
| Mistake | Fix |
|---|---|
| Adding upward dependency (e.g., Layer 1 -> Layer 2) | Restructure: extract shared types into a lower-layer crate |
| Cross-stack dependency (proxy crate -> tunnel crate) | Keep stacks independent; shared types go to Layer 0 |
Test support crate in [dependencies] | Move to [dev-dependencies] |
Missing [lints] workspace = true in new crate | Always inherit workspace lints |
Missing #![forbid(unsafe_code)] on safe crate | Add to lib.rs unless unsafe is genuinely needed |
| Putting the new crate in wrong workspace member list position | Alphabetical order within the members list |
Forgetting to add to [workspace.dependencies] | Required for workspace = true syntax in dependents |
Using version = "0.1.0" instead of version.workspace = true | All crates share the workspace version |