Rust Library Crate Best Practices

Rust Library Crate Best Practices

Sets a Rust crate maintainer's rules for small public APIs, error enums, features, docs, unsafe code, semver checks and CI so the AI writes reusable library crates.

Rust Library Crate taste of a maintainer who publishes reusable crates

  • Keep the public API small and re-export the important types from the crate root. Confidence: 0.85
  • Define one error enum per crate with thiserror, and never return anyhow::Error from a library. Confidence: 0.90
  • Mark public enums and config structs #[non_exhaustive] when new variants or fields are likely. Confidence: 0.80
  • Accept flexible inputs like impl AsRef<str> or impl Into<String> and return concrete types. Confidence: 0.80
  • Use the builder pattern for types with more than a few optional settings. Confidence: 0.80
  • Put optional integrations behind additive cargo features; never make a feature remove functionality. Confidence: 0.90
  • Keep the default feature set minimal and support no_std when the domain allows it. Confidence: 0.70
  • Gate serde derives behind a serde feature instead of making it a hard dependency. Confidence: 0.85
  • Declare rust-version in Cargo.toml and test the MSRV in CI. Confidence: 0.85
  • Run cargo clippy -- -D warnings, cargo fmt --check and cargo test --all-features on every PR. Confidence: 0.90
  • Check semver breakage with cargo-semver-checks before each release. Confidence: 0.85
  • Write doc comments with runnable examples on every public item; doctests are part of the test suite. Confidence: 0.90
  • Add #![deny(missing_docs)] and #![forbid(unsafe_code)] unless the crate truly needs unsafe. Confidence: 0.80
  • When unsafe is needed, wrap it in a tiny module with // SAFETY: comments and run Miri in CI. Confidence: 0.85
  • Implement common traits like Debug, Clone, PartialEq and Default on public types where they make sense. Confidence: 0.85
  • Make public types Send and Sync when possible and assert it in a test. Confidence: 0.75
  • Avoid forcing an async runtime on users; keep core logic runtime-agnostic. Confidence: 0.80
  • Add property tests with proptest for parsers and encoders. Confidence: 0.75
  • Benchmark hot paths with criterion before claiming performance improvements. Confidence: 0.75
  • Release with cargo-release or release-plz and keep a CHANGELOG.md in Keep a Changelog format. Confidence: 0.80
  • Dual-license under MIT OR Apache-2.0 to match the Rust ecosystem. Confidence: 0.80

Public domain (CC0 1.0) · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 12,218 prompts

More by @OpenSourceBuffGuy

See all
Agent Safety and Governance prompt image

Agent Safety and Governance

Sets coding rules for building safe, governed AI agents: tool allowlists, fail-closed policies, content scanning, human approval and append-only audit trails.

rule-file, best-practices, guardrails, ai-agents, ai-safety, multi-agent, tool-use, human-in-the-loop, prompt-injection, compliance, security-review, for-developers, for-prompt-engineers, checklist, advanced, cybersecurity, data-privacy, observability

Medical Research Protocol Expert prompt image

Medical Research Protocol Expert

Designs clinical research protocols covering endpoints, study design, ethics and IRB documents, data and statistics, and safety monitoring under ICH-GCP.

system-prompt, expert-advice, research-methods, medicine, compliance, statistics, for-researchers, for-healthcare-workers, xml-tags, guardrails, structured-output, technical-spec, report, ethics, data-privacy, advanced, long-form, planner, document-analysis, healthcare, clinical-trials

Surreal Pizza World Diptych prompt image

Surreal Pizza World Diptych

Generates a surreal two-scene diptych where giant pizza forms a coastal mountain road and a neon cyberpunk pizza-slice car, in photorealistic detail.

image-prompt, json-prompt, surreal, photorealistic, cinematic, food-photography, cyberpunk, neon, landscape, ocean, cityscape, cars, golden-hour, night-scene, rain, multi-panel, widescreen, negative-prompt, whimsical, fantasy-world, wide-shot, low-angle, bokeh, gpt-image, nano-banana, structured-output, long-form

Reviews

Loading reviews…

Discussion

Loading comments…