Skip to content

Commit d867436

Browse files
committed
Word wrapping
1 parent 4ba3247 commit d867436

File tree

1 file changed

+86
-84
lines changed

1 file changed

+86
-84
lines changed

src/types.md

Lines changed: 86 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ limited capabilities.
99

1010
## Primitive types
1111

12-
Some types are defined by the language, rather than as part of the standard library,
13-
these are called _primitive types_. Some of these are induvidual types:
12+
Some types are defined by the language, rather than as part of the standard
13+
library, these are called _primitive types_. Some of these are induvidual
14+
types:
1415

1516
* The boolean type `bool` with values `true` and `false`.
1617
* The [machine types] (integer and floating-point).
1718
* The [machine-dependent integer types].
1819
* The [textual types] `char` and `str`.
1920

20-
There are also some primitive constructs for generic types built in to the language:
21+
There are also some primitive constructs for generic types built in to the
22+
language:
2123

2224
* [Tuples]
2325
* [Arrays]
@@ -45,27 +47,27 @@ There are also some primitive constructs for generic types built in to the langu
4547
The machine types are the following:
4648

4749
* The unsigned word types `u8`, `u16`, `u32` and `u64`, with values drawn from
48-
the integer intervals [0, 2^8 - 1], [0, 2^16 - 1], [0, 2^32 - 1] and
49-
[0, 2^64 - 1] respectively.
50+
the integer intervals [0, 2^8 - 1], [0, 2^16 - 1], [0, 2^32 - 1] and [0, 2^64
51+
- 1] respectively.
5052

5153
* The signed two's complement word types `i8`, `i16`, `i32` and `i64`, with
52-
values drawn from the integer intervals [-(2^(7)), 2^7 - 1],
53-
[-(2^(15)), 2^15 - 1], [-(2^(31)), 2^31 - 1], [-(2^(63)), 2^63 - 1]
54-
respectively.
54+
values drawn from the integer intervals [-(2^(7)), 2^7 - 1], [-(2^(15)), 2^15
55+
- 1], [-(2^(31)), 2^31 - 1], [-(2^(63)), 2^63 - 1] respectively.
5556

5657
* The IEEE 754-2008 `binary32` and `binary64` floating-point types: `f32` and
5758
`f64`, respectively.
5859

5960
### Machine-dependent integer types
6061

61-
The `usize` type is an unsigned integer type with the same number of bits as the
62-
platform's pointer type. It can represent every memory address in the process.
62+
The `usize` type is an unsigned integer type with the same number of bits as
63+
the platform's pointer type. It can represent every memory address in the
64+
process.
6365

6466
The `isize` type is a signed integer type with the same number of bits as the
6567
platform's pointer type. The theoretical upper bound on object and array size
66-
is the maximum `isize` value. This ensures that `isize` can be used to calculate
67-
differences between pointers into an object or array and can address every byte
68-
within an object along with one byte past the end.
68+
is the maximum `isize` value. This ensures that `isize` can be used to
69+
calculate differences between pointers into an object or array and can address
70+
every byte within an object along with one byte past the end.
6971

7072
## Textual types
7173

@@ -79,8 +81,8 @@ string.
7981

8082
A value of type `str` is a Unicode string, represented as an array of 8-bit
8183
unsigned bytes holding a sequence of UTF-8 code points. Since `str` is a
82-
[dynamically sized type], it is not a _first-class_ type, but can only be instantiated
83-
through a pointer type, such as `&str`.
84+
[dynamically sized type], it is not a _first-class_ type, but can only be
85+
instantiated through a pointer type, such as `&str`.
8486

8587
## Tuple types
8688

@@ -91,8 +93,8 @@ Tuple types and values are denoted by listing the types or values of their
9193
elements, respectively, in a parenthesized, comma-separated list.
9294

9395
Because tuple elements don't have a name, they can only be accessed by
94-
pattern-matching or by using `N` directly as a field to access the
95-
`N`th element.
96+
pattern-matching or by using `N` directly as a field to access the `N`th
97+
element.
9698

9799
An example of a tuple type and its use:
98100

@@ -160,25 +162,24 @@ expression](expressions.html#struct-expressions).
160162

161163
The memory layout of a `struct` is undefined by default to allow for compiler
162164
optimizations like field reordering, but it can be fixed with the
163-
`#[repr(...)]` attribute. In either case, fields may be given in any order in
164-
a corresponding struct *expression*; the resulting `struct` value will always
165+
`#[repr(...)]` attribute. In either case, fields may be given in any order in a
166+
corresponding struct *expression*; the resulting `struct` value will always
165167
have the same memory layout.
166168

167169
The fields of a `struct` may be qualified by [visibility
168-
modifiers](visibility-and-privacy.html), to allow access to data in a
169-
struct outside a module.
170+
modifiers](visibility-and-privacy.html), to allow access to data in a struct
171+
outside a module.
170172

171173
A _tuple struct_ type is just like a struct type, except that the fields are
172174
anonymous.
173175

174-
A _unit-like struct_ type is like a struct type, except that it has no
175-
fields. The one value constructed by the associated [struct
176-
expression](expressions.html#struct-expressions) is the only value that inhabits such a
177-
type.
176+
A _unit-like struct_ type is like a struct type, except that it has no fields.
177+
The one value constructed by the associated [struct
178+
expression](expressions.html#struct-expressions) is the only value that
179+
inhabits such a type.
178180

179-
[^structtype]: `struct` types are analogous to `struct` types in C,
180-
the *record* types of the ML family,
181-
or the *struct* types of the Lisp family.
181+
[^structtype]: `struct` types are analogous to `struct` types in C, the
182+
*record* types of the ML family, or the *struct* types of the Lisp family.
182183

183184
## Enumerated types
184185

@@ -203,8 +204,8 @@ named reference to an [`enum` item](items.html#enumerations).
203204

204205
## Union types
205206

206-
A *union type* is a nominal, heterogeneous C-like union, denoted by the name
207-
of a [`union` item](items.html#unions).
207+
A *union type* is a nominal, heterogeneous C-like union, denoted by the name of
208+
a [`union` item](items.html#unions).
208209

209210
A union contains the value of any one of its fields. Since the accessing the
210211
wrong field can cause unexpected or undefined behaviour, it requires `unsafe`,
@@ -221,13 +222,14 @@ recursive. That is, each `enum` variant or `struct` or `union` field may refer,
221222
directly or indirectly, to the enclosing `enum` or `struct` type itself. Such
222223
recursion has restrictions:
223224

224-
* Recursive types must include a nominal type in the recursion
225-
(not mere [type definitions](../grammar.html#type-definitions),
226-
or other structural types such as [arrays](#array-and-slice-types) or [tuples](#tuple-types)).
227-
* The size of a recursive type must be finite;
228-
in other words the recursive fields of the type must be [pointer types](#pointer-types).
229-
* Recursive type definitions can cross module boundaries, but not module *visibility* boundaries,
230-
or crate boundaries (in order to simplify the module system and type checker).
225+
* Recursive types must include a nominal type in the recursion (not mere [type
226+
definitions](../grammar.html#type-definitions), or other structural types
227+
such as [arrays](#array-and-slice-types) or [tuples](#tuple-types)).
228+
* The size of a recursive type must be finite; in other words the recursive
229+
fields of the type must be [pointer types](#pointer-types).
230+
* Recursive type definitions can cross module boundaries, but not module
231+
*visibility* boundaries, or crate boundaries (in order to simplify the module
232+
system and type checker).
231233

232234
An example of a *recursive* type and its use:
233235

@@ -243,8 +245,8 @@ let a: List<i32> = List::Cons(7, Box::new(List::Cons(13, Box::new(List::Nil))));
243245
## Pointer types
244246

245247
All pointers in Rust are explicit first-class values. They can be copied,
246-
stored into data structs, and returned from functions. There are two
247-
varieties of pointer in Rust:
248+
stored into data structs, and returned from functions. There are two varieties
249+
of pointer in Rust:
248250

249251
### Shared references (`&`)
250252

@@ -261,10 +263,9 @@ keep it alive during the scope of the reference itself.
261263

262264
### Mutable references (`&mut`)
263265

264-
These also point to memory owned by some other value. A mutable reference
265-
type is written `&mut type` or `&'a mut type`. A mutable reference (that
266-
hasn't been borrowed) is the only way to access the value it points to, so
267-
is not `Copy`.
266+
These also point to memory owned by some other value. A mutable reference type
267+
is written `&mut type` or `&'a mut type`. A mutable reference (that hasn't been
268+
borrowed) is the only way to access the value it points to, so is not `Copy`.
268269

269270
### Raw pointers (`*const` and `*mut`)
270271

@@ -283,8 +284,8 @@ types](#dynamically-sized-types) they also have their addition data compared.
283284

284285
### Smart Pointers
285286

286-
The standard library contains additional 'smart pointer' types beyond references
287-
and raw pointers.
287+
The standard library contains additional 'smart pointer' types beyond
288+
references and raw pointers.
288289

289290
## Function item types
290291

@@ -297,8 +298,8 @@ need to contain an actual function pointer, and no indirection is needed when
297298
the function is called.
298299

299300
There is currently no syntax that directly refers to a function item type, but
300-
the compiler will display the type as something like `fn() {foo::<u32>}` in error
301-
messages.
301+
the compiler will display the type as something like `fn() {foo::<u32>}` in
302+
error messages.
302303

303304
Because the function item type explicitly identifies the function, the item
304305
types of different functions - different items, or the same item with different
@@ -310,11 +311,11 @@ let x = &mut foo::<i32>;
310311
*x = foo::<u32>; //~ ERROR mismatched types
311312
```
312313

313-
However, there is a [coercion] from function items to [function pointers](#function-pointer-types)
314-
with the same signature, which is triggered not only when a function item
315-
is used when a function pointer is directly expected, but also when different
316-
function item types with the same signature meet in different arms of the same
317-
`if` or `match`:
314+
However, there is a [coercion] from function items to [function
315+
pointers](#function-pointer-types) with the same signature, which is triggered
316+
not only when a function item is used when a function pointer is directly
317+
expected, but also when different function item types with the same signature
318+
meet in different arms of the same `if` or `match`:
318319

319320
[coercion]: type-coercions.html
320321

@@ -363,29 +364,26 @@ x = bo(5,7);
363364
A [closure expression](expressions.html#closure-expressions) produces a closure
364365
value with a unique, anonymous type that cannot be written out.
365366

366-
Depending on the requirements of the closure, its type implements one or
367-
more of the closure traits:
367+
Depending on the requirements of the closure, its type implements one or more
368+
of the closure traits:
368369

369-
* `FnOnce`
370-
: The closure can be called once. A closure called as `FnOnce`
371-
can move out values from its environment.
370+
* `FnOnce` : The closure can be called once. A closure called as `FnOnce` can
371+
move out values from its environment.
372372

373-
* `FnMut`
374-
: The closure can be called multiple times as mutable. A closure called as
375-
`FnMut` can mutate values from its environment. `FnMut` inherits from
376-
`FnOnce` (i.e. anything implementing `FnMut` also implements `FnOnce`).
373+
* `FnMut` : The closure can be called multiple times as mutable. A closure
374+
called as `FnMut` can mutate values from its environment. `FnMut` inherits
375+
from `FnOnce` (i.e. anything implementing `FnMut` also implements `FnOnce`).
377376

378-
* `Fn`
379-
: The closure can be called multiple times through a shared reference. A
380-
closure called as `Fn` can neither move out from nor mutate captured
381-
variables, but read-only access to such values is allowed. Using `move` to
382-
capture variables by value is allowed so long as they aren't mutated or
383-
moved in the body of the closure. `Fn` inherits from `FnMut`, which itself
384-
inherits from `FnOnce`.
377+
* `Fn` : The closure can be called multiple times through a shared reference. A
378+
closure called as `Fn` can neither move out from nor mutate captured
379+
variables, but read-only access to such values is allowed. Using `move` to
380+
capture variables by value is allowed so long as they aren't mutated or moved
381+
in the body of the closure. `Fn` inherits from `FnMut`, which itself inherits
382+
from `FnOnce`.
385383

386-
Closures that don't use anything from their environment ("non capturing closures")
387-
can be coerced to function pointers (`fn`) with the matching signature.
388-
To adopt the example from the section above:
384+
Closures that don't use anything from their environment ("non capturing
385+
closures") can be coerced to function pointers (`fn`) with the matching
386+
signature. To adopt the example from the section above:
389387

390388
```rust
391389
let add = |x, y| x + y;
@@ -414,7 +412,8 @@ function pointer is loaded from the trait object vtable and invoked indirectly.
414412
The actual implementation for each vtable entry can vary on an object-by-object
415413
basis.
416414

417-
Note that for a trait object types only exist for _object-safe_ traits ([RFC 255]):
415+
Note that for a trait object types only exist for _object-safe_ traits ([RFC
416+
255]):
418417

419418
[RFC 255]: https://github.com/rust-lang/rfcs/blob/master/text/0255-object-safety.md
420419

@@ -457,8 +456,8 @@ type signature of `print`, and the cast expression in `main`.
457456

458457
Since a trait object can contain references, the lifetimes of those references
459458
need to be expressed as part of the trait object. The assumed lifetime of
460-
references held by a trait object is called its _default object lifetime bound_.
461-
These were defined in [RFC 599] and amended in [RFC 1156].
459+
references held by a trait object is called its _default object lifetime
460+
bound_. These were defined in [RFC 599] and amended in [RFC 1156].
462461

463462
[RFC 599]: https://github.com/rust-lang/rfcs/blob/master/text/0599-default-object-bound.md
464463
[RFC 1156]: https://github.com/rust-lang/rfcs/blob/master/text/1156-adjust-default-object-bounds.md
@@ -480,8 +479,9 @@ Box<Foo + 'static>
480479
```
481480

482481
The `+ 'static` and `+ 'a` refer to the default bounds of those kinds of trait
483-
objects, and also to how you can directly override them. Note that the innermost
484-
object sets the bound, so `&'a Box<Foo>` is still `&'a Box<Foo + 'static>`.
482+
objects, and also to how you can directly override them. Note that the
483+
innermost object sets the bound, so `&'a Box<Foo>` is still `&'a Box<Foo +
484+
'static>`.
485485

486486
For traits that have lifetime parameters of their own, the default bound is
487487
based on that lifetime parameter:
@@ -508,7 +508,8 @@ trait [`Sized`]. A type with a size that is known only at run-time is called a
508508
_dynamically sized type_ (_DST_) or unsized type. [Slices] and [trait objects]
509509
are two of the most DSTs. Such types can only be used in certain cases:
510510

511-
* [Pointer types] to DSTs are sized but have twice the size of pointers to sized types
511+
* [Pointer types] to DSTs are sized but have twice the size of pointers to
512+
sized types
512513
* Pointers to slices also store the number of elements of the slice.
513514
* Pointers to trait objects also store a pointer to a vtable.
514515
* Traits may be implemented for DSTs
@@ -560,14 +561,15 @@ fn to_vec<A: Clone>(xs: &[A]) -> Vec<A> {
560561
}
561562
```
562563

563-
Here, `first` has type `A`, referring to `to_vec`'s `A` type parameter; and `rest`
564-
has type `Vec<A>`, a vector with element type `A`.
564+
Here, `first` has type `A`, referring to `to_vec`'s `A` type parameter; and
565+
`rest` has type `Vec<A>`, a vector with element type `A`.
565566

566567
## Self types
567568

568-
The special type `Self` has a meaning within traits and impls. In a trait definition, it refers
569-
to an implicit type parameter representing the "implementing" type. In an impl,
570-
it is an alias for the implementing type. For example, in:
569+
The special type `Self` has a meaning within traits and impls. In a trait
570+
definition, it refers to an implicit type parameter representing the
571+
"implementing" type. In an impl, it is an alias for the implementing type. For
572+
example, in:
571573

572574
```rust
573575
pub trait From<T> {
@@ -581,8 +583,8 @@ impl From<i32> for String {
581583
}
582584
```
583585

584-
The notation `Self` in the impl refers to the implementing type: `String`. In another
585-
example:
586+
The notation `Self` in the impl refers to the implementing type: `String`. In
587+
another example:
586588

587589
```rust
588590
trait Printable {

0 commit comments

Comments
 (0)