Is there something like "Rust Core Guidelines" (like "C++ Core Guidelines")?

Hello everyone!

For C++, there is an article called "C++ Core Guidelines" that lists some rules for C++ code to help people write better C++ code. Although some of the advice is language-agnostic, a lot of them are C++-specific, and Rust has its own features that have to be covered (extending other people's types with traits, error handling, async functions), so I wonder, are there similar advice articles for Rust?

The Rust API Guidelines may be the sort of thing you are looking for. Some other style things are enforced by rustfmt, and running clippy can help with ensuring idioms are followed.

8 Likes

In Rust, the preferred solution is to avoid the need for such document to exist. The language is designed to be easier to statically analyze, and makes the compiler check and enforce as much of the "guidelines" as possible, especially the important stuff around safety and correctness.

For more subjective and optional guidelines, there's still focus on not having such document, but an automation instead. There's cargo clippy with hundreds of lints detecting unidiomatic or suspiciously looking code, and a system for selectively allowing or disallowing these code patterns. Whenever a gotcha is discovered in Rust, instead of documenting the best practice that avoids it, someone writes a Clippy lint for it.

For general advice how to write idiomatic code, see

and also check out the most popular crates. They are often de-facto standards of how things are done in Rust:

17 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.