Rust conventions
Rule#
Every Rust crate in the fleet shares the same baseline: edition 2024, clippy pedantic with a fixed allowlist, workspace-inherited lints, and git-based distribution (no crates.io). These apply to products, libraries, and CLI tools alike.
Workspace lints#
Define lints once at the workspace root and inherit them in every member:
# workspace root Cargo.toml
[workspace.lints.clippy]
pedantic = { level = "warn", priority = 0 }
missing_errors_doc = { level = "allow", priority = 1 }
panic = { level = "warn", priority = 1 }
implicit_hasher = { level = "allow", priority = 1 }
# each member Cargo.toml
[lints]
workspace = true
CI enforces it: cargo clippy --workspace --all-targets -- -D warnings
(ci-cd.md). Template: templates/rust/Cargo-workspace-lints.toml.
Edition & toolchain#
- Edition 2024 everywhere.
- A
.cargo/config.tomlis required where the crate uses structured logging or fetches private deps:[build] rustflags = ["--cfg", "tracing_unstable"] # enables tracing's `valuable` support [net] git-fetch-with-cli = true # reliable SSH fetch of private crates
Dependency distribution#
- Git deps, not crates.io. Consumers pin by git ref or use workspace members:
liberror = { git = "https://github.com/charliethomson/liberror" } # public → HTTPS liblog = { git = "ssh://[email protected]/charliethomson/liblog.git" } # private → SSH libsomeproduct = { git = "ssh://[email protected]/charliethomson/libsomeproduct.git", default-features = false, features = ["tiktok", "twitch"] } - HTTPS for public repos, SSH for private ones. CI loads the
ssh_keydeploy key into anssh-agentand setsCARGO_NET_GIT_FETCH_WITH_CLI=true(ci-cd.md). - kiln and
libciare both private. A repo's.kiln/Cargo.tomltakes both over SSH, so the.kiln/build needs the deploy key andgit-fetch-with-clilike any other private dep; on a CI agent the repo'scheckout_keyprovides it:kiln = { git = "ssh://[email protected]/charliethomson/kiln.git" } # private → SSH libci = { git = "ssh://[email protected]/charliethomson/libci.git", features = ["templates"] } # private → SSH - Feature-gate optional weight (platform backends,
buildinfo, WAF bypass) so consumers opt in.
Project shape#
- Workspace-unified version placeholder; versioning is derived (versioning.md).
- Binaries declare their identifier with
product_name!("dev.thmsn.…")and publish it withset_global()inmain— the macro alone only declares it (identifiers.md). - Errors follow the error-handling trinity; shared concerns come from the
lib*ecosystem rather than being re-solved.
Checklist#
- Edition 2024;
[lints] workspace = truein every member. - Workspace clippy
pedantic = warnwith the standard allowlist; CI runs-D warnings. .cargo/config.tomlsetstracing_unstableandgit-fetch-with-cliwhere needed.- Deps are git (HTTPS public / SSH private), feature-gated where optional — including
.kiln/: kiln andlibcioverssh://. - Cross-cutting concerns pulled from
lib*, not reimplemented.