Skip to content

Commit a638b8c

Browse files
committed
Wrap to 80 characters
1 parent 4184b1b commit a638b8c

File tree

4 files changed

+64
-74
lines changed

4 files changed

+64
-74
lines changed

src/about.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
# Rust API Guidelines
22

3-
This is a set of recommendations on how to design and present APIs for
4-
the Rust programming language. They are authored largely by the Rust
5-
library team, based on experiences building the Rust standard library
6-
and other crates in the Rust ecosystem.
3+
This is a set of recommendations on how to design and present APIs for the Rust
4+
programming language. They are authored largely by the Rust library team, based
5+
on experiences building the Rust standard library and other crates in the Rust
6+
ecosystem.
77

8-
These are only guidelines, some more firm than others. In some cases
9-
they are vague and still in development. Rust crate authors should
10-
consider them as a set of important considerations in the development
11-
of idiomatic and interoperable Rust libraries, to use as they see
12-
fit. These guidelines should not in any way be considered a mandate
13-
that crate authors must follow, though they may find that crates that
14-
conform well to these guidelines integrate better with the existing
15-
crate ecosystem than those that do not.
8+
These are only guidelines, some more firm than others. In some cases they are
9+
vague and still in development. Rust crate authors should consider them as a set
10+
of important considerations in the development of idiomatic and interoperable
11+
Rust libraries, to use as they see fit. These guidelines should not in any way
12+
be considered a mandate that crate authors must follow, though they may find
13+
that crates that conform well to these guidelines integrate better with the
14+
existing crate ecosystem than those that do not.
1615

17-
This books is organized in two parts: the concise [checklist] of all
18-
individual guidelines, suitable for quick scanning during crate
19-
reviews; and topical chapters containing explanations of the
20-
guidelines in detail.
16+
This books is organized in two parts: the concise [checklist] of all individual
17+
guidelines, suitable for quick scanning during crate reviews; and topical
18+
chapters containing explanations of the guidelines in detail.
2119

2220
If you are interested in contributing to the API guidelines, check out
2321
[contributing.md] and join our [Gitter channel].

src/future-proofing.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ pub fn my_transform<I: Iterator>(input: I) -> impl Iterator<Item = (usize, I::It
125125
<a id="c-struct-bounds"></a>
126126
## Data structures do not duplicate derived trait bounds (C-STRUCT-BOUNDS)
127127

128-
Generic data structures should not use trait bounds that can be derived or don't otherwise
129-
add semantic value.
130-
Each trait in the `derive` attribute will be expanded into a separate `impl` block that
131-
only applies to generic arguments that implement that trait.
128+
Generic data structures should not use trait bounds that can be derived or don't
129+
otherwise add semantic value. Each trait in the `derive` attribute will be
130+
expanded into a separate `impl` block that only applies to generic arguments
131+
that implement that trait.
132132

133133
```rust
134134
// Prefer this:
@@ -141,9 +141,8 @@ struct Bad<T: Clone + Debug + PartialEq> { /* ... */ }
141141
```
142142

143143
Duplicating derived traits as bounds on `Bad` is unnecessary and a
144-
backwards-compatibiliity hazard.
145-
To illustrate this point, consider deriving `PartialOrd` on the structures in the
146-
previous example:
144+
backwards-compatibiliity hazard. To illustrate this point, consider deriving
145+
`PartialOrd` on the structures in the previous example:
147146

148147
```rust
149148
// Non-breaking change:
@@ -155,10 +154,10 @@ struct Good<T> { /* ... */ }
155154
struct Bad<T: Clone + Debug + PartialEq + PartialOrd> { /* ... */ }
156155
```
157156

158-
Generally speaking, adding a trait bound to a data structure is a breaking change
159-
because every consumer of that structure will need to start satisfying the additional bound.
160-
Deriving more traits from the standard library using the `derive` attribute is not a
161-
breaking change.
157+
Generally speaking, adding a trait bound to a data structure is a breaking
158+
change because every consumer of that structure will need to start satisfying
159+
the additional bound. Deriving more traits from the standard library using the
160+
`derive` attribute is not a breaking change.
162161

163162
The following traits should always be avoided in bounds on data structures:
164163

@@ -173,11 +172,10 @@ The following traits should always be avoided in bounds on data structures:
173172
- `DeserializeOwned`
174173

175174
There's a grey area around other non-derivable trait bounds that aren't strictly
176-
required by the structure definition, like `Read` or `Write`.
177-
They may communicate the intented behaviour of the type better in its definition
178-
but also limits future extensibility.
179-
Including semantically useful trait bounds on data structures is still less
180-
problematic than including derivable traits as bounds.
175+
required by the structure definition, like `Read` or `Write`. They may
176+
communicate the intented behaviour of the type better in its definition but also
177+
limits future extensibility. Including semantically useful trait bounds on data
178+
structures is still less problematic than including derivable traits as bounds.
181179

182180
### Exceptions
183181

src/necessities.md

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,22 @@ impl From<other_crate::Error> for Error {
4444
<a id="c-permissive"></a>
4545
## Crate and its dependencies have a permissive license (C-PERMISSIVE)
4646

47-
The software produced by the Rust project is dual-licensed, under
48-
either the [MIT] or [Apache 2.0] licenses. Crates that simply need the
49-
maximum compatibility with the Rust ecosystem are recommended to do
50-
the same, in the manner described herein. Other options are described
51-
below.
47+
The software produced by the Rust project is dual-licensed, under either the
48+
[MIT] or [Apache 2.0] licenses. Crates that simply need the maximum
49+
compatibility with the Rust ecosystem are recommended to do the same, in the
50+
manner described herein. Other options are described below.
5251

53-
These API guidelines do not provide a detailed explanation of Rust's
54-
license, but there is a small amount said in the [Rust FAQ]. These
55-
guidelines are concerned with matters of interoperability with Rust,
56-
and are not comprehensive over licensing options.
52+
These API guidelines do not provide a detailed explanation of Rust's license,
53+
but there is a small amount said in the [Rust FAQ]. These guidelines are
54+
concerned with matters of interoperability with Rust, and are not comprehensive
55+
over licensing options.
5756

5857
[MIT]: https://github.com/rust-lang/rust/blob/master/LICENSE-MIT
5958
[Apache 2.0]: https://github.com/rust-lang/rust/blob/master/LICENSE-APACHE
6059
[Rust FAQ]: https://www.rust-lang.org/en-US/faq.html#why-a-dual-mit-asl2-license
6160

62-
To apply the Rust license to your project, define the `license` field
63-
in your `Cargo.toml` as:
61+
To apply the Rust license to your project, define the `license` field in your
62+
`Cargo.toml` as:
6463

6564
```toml
6665
[package]
@@ -91,18 +90,17 @@ for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
9190
dual licensed as above, without any additional terms or conditions.
9291
```
9392

94-
Besides the dual MIT/Apache-2.0 license, another common licensing approach
95-
used by Rust crate authors is to apply a single permissive license such as
96-
MIT or BSD. This license scheme is also entirely compatible with Rust's,
97-
because it imposes the minimal restrictions of Rust's MIT license.
93+
Besides the dual MIT/Apache-2.0 license, another common licensing approach used
94+
by Rust crate authors is to apply a single permissive license such as MIT or
95+
BSD. This license scheme is also entirely compatible with Rust's, because it
96+
imposes the minimal restrictions of Rust's MIT license.
9897

99-
Crates that desire perfect license compatibility with Rust are not
100-
recommended to choose only the Apache license. The Apache license,
101-
though it is a permissive license, imposes restrictions beyond the MIT
102-
and BSD licenses that can discourage or prevent their use in some
103-
scenarios, so Apache-only software cannot be used in some situations
104-
where most of the Rust runtime stack can.
98+
Crates that desire perfect license compatibility with Rust are not recommended
99+
to choose only the Apache license. The Apache license, though it is a permissive
100+
license, imposes restrictions beyond the MIT and BSD licenses that can
101+
discourage or prevent their use in some scenarios, so Apache-only software
102+
cannot be used in some situations where most of the Rust runtime stack can.
105103

106104
The license of a crate's dependencies can affect the restrictions on
107-
distribution of the crate itself, so a permissively-licensed crate
108-
should generally only depend on permissively-licensed crates.
105+
distribution of the crate itself, so a permissively-licensed crate should
106+
generally only depend on permissively-licensed crates.

src/predictability.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -181,25 +181,21 @@ a type. Sometimes it takes no arguments, as in the examples above. Sometimes it
181181
does take arguments, like [`Box::new`] which is passed the value to place in the
182182
`Box`.
183183

184-
Some types' constructors, most notably I/O resource types, use
185-
distinct naming conventions for their constructors, as in
186-
[`File::open`], [`Mmap::open`], [`TcpStream::connect`], and
187-
[`UpdSocket::bind`]. In these cases names are chosen as appropriate
188-
for the domain.
189-
190-
Often there are multiple ways to construct a type. It's common in
191-
these cases for secondary constructors to be be suffixed, `_with_foo`,
192-
as in [`Mmap::open_with_offset`]. If your type has a multiplicity of
193-
construction options though, consider the builder
194-
pattern ([C-BUILDER]) instead.
195-
196-
Some constructors are "conversion constructors", methods that create a
197-
new type from an existing value of a different type. These typically
198-
have names begining with `from_` as in
199-
[`std::io::Error::from_raw_os_error`]. Note also though the `From`
200-
trait ([C-CONV-TRAITS]), which is quite similar. Guidelines for
201-
writing a `From` implementation vs. writing `from_foo` need further
202-
examination.
184+
Some types' constructors, most notably I/O resource types, use distinct naming
185+
conventions for their constructors, as in [`File::open`], [`Mmap::open`],
186+
[`TcpStream::connect`], and [`UpdSocket::bind`]. In these cases names are chosen
187+
as appropriate for the domain.
188+
189+
Often there are multiple ways to construct a type. It's common in these cases
190+
for secondary constructors to be be suffixed, `_with_foo`, as in
191+
[`Mmap::open_with_offset`]. If your type has a multiplicity of construction
192+
options though, consider the builder pattern ([C-BUILDER]) instead.
193+
194+
Some constructors are "conversion constructors", methods that create a new type
195+
from an existing value of a different type. These typically have names begining
196+
with `from_` as in [`std::io::Error::from_raw_os_error`]. Note also though the
197+
`From` trait ([C-CONV-TRAITS]), which is quite similar. Guidelines for writing a
198+
`From` implementation vs. writing `from_foo` need further examination.
203199

204200
Note that it is common and expected for types to implement both `Default` and a
205201
`new` constructor. For types that have both, they should have the same behavior.

0 commit comments

Comments
 (0)