A comprehensive Rust library providing structured enums and utilities for the official Rust API Guidelines. This crate helps developers follow Rust best practices by providing programmatic access to API design principles.
This library implements the complete Rust API Guidelines as structured enums, making it easier to:
- Reference specific guidelines in code
- Build linting tools and code analyzers
- Document API design decisions
- Ensure code quality and consistency
- Create educational materials and examples
- Generate API documentation with guideline references
Add this to your Cargo.toml:
[dependencies]
api-guidelines = "0.1.0"use api_guidelines::{Naming, Interoperability, Predictability, Flexibility};
fn main() {
// Reference naming conventions
let naming_convention = Naming::C_CASE;
let conversion_guideline = Naming::C_CONV;
// Reference interoperability guidelines
let common_traits = Interoperability::C_COMMON_TRAITS;
let conversion_traits = Interoperability::C_CONV_TRAITS;
// Reference predictability guidelines
let smart_ptr_guideline = Predictability::C_SMART_PTR;
let constructor_guideline = Predictability::C_CTOR;
// Use in documentation or tooling
println!("Following guideline: {:?}", naming_convention);
println!("Following guideline: {:?}", conversion_traits);
println!("Following guideline: {:?}", smart_ptr_guideline);
}C_CASE- Casing conventions (UpperCamelCase vs snake_case)C_CONV- Conversion method naming (as_, to_, into_)C_GETTER- Getter naming conventionsC_ITER- Iterator method namingC_ITER_TY- Iterator type namingC_FEATURE- Feature naming conventionsC_WORD_ORDER- Consistent word order
C_COMMON_TRAITS- Common trait implementationsC_CONV_TRAITS- Standard conversion traitsC_COLLECT- FromIterator and Extend implementationsC_SERDE- Serde serialization supportC_SEND_SYNC- Send and Sync implementationsC_GOOD_ERR- Error type best practicesC_NUM_FMT- Number formatting traitsC_RW_VALUE- Reader/Writer function parameters
C_SMART_PTR- Smart pointers don't add inherent methodsC_CONV_SPECIFIC- Conversions live on the most specific typeC_METHOD- Functions with clear receivers are methodsC_NO_OUT- Functions don't take out-parametersC_OVERLOAD- Operator overloads are unsurprisingC_DEREF- Only smart pointers implement Deref and DerefMutC_CTOR- Constructors are static, inherent methods
C_INTERMEDIATE- Functions expose intermediate resultsC_CALLER_CONTROL- Caller decides where to copy and place dataC_GENERIC- Functions minimize assumptions using genericsC_OBJECT- Traits are object-safe if useful as trait objects
C_NEWTYPE- Newtypes provide static distinctionsC_CUSTOM_TYPE- Arguments convey meaning through typesC_BITFLAG- Types for flags are bitflags, not enumsC_BUILDER- Builders enable construction of complex values
C_VALIDATE- Functions validate their argumentsC_DTOR_FAIL- Destructors never failC_DTOR_BLOCK- Destructors that may block have alternatives
C_DEBUG- All public types implement DebugC_DEBUG_NONEMPTY- Debug representation is never empty
C_SEALED- Sealed traits protect against downstream implementationsC_STRUCT_PRIVATE- Structs have private fieldsC_NEWTYPE_HIDE- Newtypes encapsulate implementation detailsC_STRUCT_BOUNDS- Data structures don't duplicate derived trait bounds
C_STABLE- Public dependencies of stable crates are stableC_PERMISSIVE- Crate and dependencies have permissive license
C_CRATE_DOC- Crate level docs are thorough with examplesC_EXAMPLE- All items have rustdoc examplesC_QUESTION_MARK- Examples use ?, not try!, not unwrapC_FAILURE- Function docs include error, panic, and safety considerationsC_LINK- Prose contains hyperlinks to relevant thingsC_METADATA- Cargo.toml includes all common metadataC_RELNOTES- Release notes document all significant changesC_HIDDEN- Rustdoc doesn't show unhelpful implementation details
C_EVOCATIVE- Input syntax is evocative of the outputC_MACRO_ATTR- Item macros compose well with attributesC_ANYWHERE- Item macros work anywhere items are allowedC_MACRO_VIS- Item macros support visibility specifiersC_MACRO_TY- Type fragments are flexible
Full documentation is available at docs.rs/api-guidelines.
Contributions are welcome! Please feel free to submit pull requests or open issues.
This project is licensed under the MIT License - see the LICENSE file for details.
- Based on the official Rust API Guidelines