api-guidelines
api-guidelines copied to clipboard
Rust API guidelines
As MIT still require attribution, by preserving the license statement, it isn't the most permissible license possible, hence why 0BSD and MIT-0 licenses have arisen, for those who want to...
Extend C-DEREF guideline to say smart pointers should always be transparent in Debug representation
The canonical Debug implementation for **any** type that implements Deref is: ```rust Debug::fmt(&**self, formatter) ``` This principle came up during libs team discussion of https://github.com/rust-lang/rust/pull/48553.
https://github.com/rust-lang-nursery/api-guidelines/issues/135#issuecomment-343698387 suggests a nice one: > I've been using `PascalCase!` for macros that expand into types. (e.g. `Array![i32; 5; 4; 3]` which expands into `[[[i32; 3]; 4]; 5]`) I did...
This PR tries to codify what's being brought up in this forum thread: https://users.rust-lang.org/t/do-people-not-care-about-printable-error-chains-a-k-a-how-to-nicely-implement-display-for-an-error/35362 These guidelines are still lacking a lot of information about how to design error types well...
C-ITER recommends implementing three methods for collections: `iter()`, `iter_mut()` and `into_iter()`. It fails to mention that `into_iter()` can (and probably should?) be implemented by implementing the `IntoIterator` trait. Additionally, the...
According to the [rustdoc book](https://doc.rust-lang.org/rustdoc/documentation-tests.html#using--in-doc-tests): > As of version 1.34.0, one can also omit the fn main(), but you will have to disambiguate the error type: > > ```rust >...
The C-STRUCT-PRIVATE recommendation talks about a single struct field being public or private. It does not mention what happens when all fields of a struct are public, e.g., in that...
https://github.com/rust-lang/rfcs/pull/1860#issuecomment-279848322 gives an interesting reason to consider not following the C-SMART-PTR guideline. In that case we decided to follow the guideline anyway, even though the motivation for the guideline does...
Can we expand the language of C-COMMON-TRAITS to help making decisions for enum types implementing non-trivial traits, specially `Ord`/`PartialOrd` and `Default`? I think the question I face in designing the...
[C-NEWTYPE-HIDE](https://rust-lang-nursery.github.io/api-guidelines/future-proofing.html#newtypes-encapsulate-implementation-details-c-newtype-hide) neglects to mention something that I feel is quite important: `Enumerate` does not just implement `Iterator`; it may also implement some or all of `Debug`, `Clone`, `FusedIterator`, `ExactSizeIterator` and...