Skip to content

Commit 0a15f29

Browse files
committed
Split Types Chapter
This splits the types chapter into multiple subchapters. I tried to avoid content changes, but I ended up with a few changes: - Added overview links in `types.md`, and a separate discussion of type expressions. - Split array and slice into separate chapters. Although there is some overlap between them, I feel like it was awkward explaining one and then the other. I also felt it conflated the two too much since slices can be used for more than arrays. - Combined `Self` section with the one on the paths page. - Added a basic redirector for external links. Some pages may seem a little bare now, but I think each type page has potential to be expanded and improved in the future.
1 parent 8401995 commit 0a15f29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1010
-904
lines changed

src/SUMMARY.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@
6767

6868
- [Type system](type-system.md)
6969
- [Types](types.md)
70+
- [Boolean type](types/boolean.md)
71+
- [Numeric types](types/numeric.md)
72+
- [Textual types](types/textual.md)
73+
- [Never type](types/never.md)
74+
- [Tuple types](types/tuple.md)
75+
- [Array types](types/array.md)
76+
- [Slice types](types/slice.md)
77+
- [Struct types](types/struct.md)
78+
- [Enumerated types](types/enum.md)
79+
- [Union types](types/union.md)
80+
- [Function item types](types/function-item.md)
81+
- [Closure types](types/closure.md)
82+
- [Pointer types](types/pointer.md)
83+
- [Function pointer types](types/function-pointer.md)
84+
- [Trait object types](types/trait-object.md)
85+
- [Impl trait type](types/impl-trait.md)
7086
- [Dynamically Sized Types](dynamically-sized-types.md)
7187
- [Type layout](type-layout.md)
7288
- [Interior mutability](interior-mutability.md)

src/const_eval.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ A _const context_ is one of the following:
5151
* [statics]
5252
* [enum discriminants]
5353

54-
[array type length expressions]: types.html#array-and-slice-types
54+
[array type length expressions]: types/array.html
5555
[enum discriminants]: items/enumerations.html#custom-discriminant-values-for-field-less-enumerations
5656
[constants]: items/constant-items.html
5757
[statics]: items/static-items.html
@@ -68,7 +68,7 @@ A _const context_ is one of the following:
6868
[block expressions]: expressions/block-expr.html
6969
[field]: expressions/field-expr.html
7070
[array indexing]: expressions/array-expr.html#array-and-slice-indexing-expressions
71-
[slice]: types.html#array-and-slice-types
71+
[slice]: types/slice.html
7272
[range expressions]: expressions/range-expr.html
7373
[closure expressions]: expressions/closure-expr.html
7474
[negation]: expressions/operator-expr.html#negation-operators

src/destructors.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ variable or field from being dropped automatically.
8282
[Assignment]: expressions/operator-expr.html#assignment-expressions
8383
[`std::ops::Drop::drop`]: ../std/ops/trait.Drop.html
8484
[RFC 1857]: https://github.com/rust-lang/rfcs/blob/master/text/1857-stabilize-drop-order.md
85-
[struct]: types.html#struct-types
86-
[tuple]: types.html#tuple-types
87-
[enum variant]: types.html#enumerated-types
88-
[array]: types.html#array-and-slice-types
89-
[closure]: types.html#closure-types
90-
[Trait objects]: types.html#trait-objects
85+
[struct]: types/struct.html
86+
[tuple]: types/tuple.html
87+
[enum variant]: types/enum.html
88+
[array]: types/array.html
89+
[closure]: types/closure.html
90+
[Trait objects]: types/trait-object.html
9191
[`std::ptr::drop_in_place`]: ../std/ptr/fn.drop_in_place.html
9292
[`std::mem::forget`]: ../std/mem/fn.forget.html
9393
[`std::mem::ManuallyDrop`]: ../std/mem/struct.ManuallyDrop.html

src/dynamically-sized-types.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ Notably: [variables], function parameters, [const] and [static] items must be
2424
`Sized`.
2525

2626
[sized]: special-types-and-traits.html#sized
27-
[Slices]: types.html#array-and-slice-types
28-
[trait objects]: types.html#trait-objects
29-
[Pointer types]: types.html#pointer-types
27+
[Slices]: types/slice.html
28+
[trait objects]: types/trait-object.html
29+
[Pointer types]: types/pointer.html
3030
[variables]: variables.html
3131
[const]: items/constant-items.html
3232
[static]: items/static-items.html

src/expressions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ They are never allowed before:
316316
[let statement]: statements.html#let-statements
317317
[Mutable `static` items]: items/static-items.html#mutable-statics
318318
[const contexts]: const_eval.html
319-
[slice]: types.html#array-and-slice-types
319+
[slice]: types/slice.html
320320
[statement]: statements.html
321321
[static variables]: items/static-items.html
322322
[Temporary values]: #temporary-lifetimes

src/expressions/array-expr.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
> &nbsp;&nbsp; &nbsp;&nbsp; [_Expression_] ( `,` [_Expression_] )<sup>\*</sup> `,`<sup>?</sup>\
1111
> &nbsp;&nbsp; | [_Expression_] `;` [_Expression_]
1212
13-
An _[array](types.html#array-and-slice-types) expression_ can be written by
13+
An _[array](types/array.html) expression_ can be written by
1414
enclosing zero or more comma-separated expressions of uniform type in square
1515
brackets. This produces and array containing each of these values in the
1616
order they are written.
@@ -44,7 +44,7 @@ expressions].
4444
> _IndexExpression_ :\
4545
> &nbsp;&nbsp; [_Expression_] `[` [_Expression_] `]`
4646
47-
[Array and slice](types.html#array-and-slice-types)-typed expressions can be
47+
[Array](types/array.html) and [slice](types/slice.html)-typed expressions can be
4848
indexed by writing a square-bracket-enclosed expression of type `usize` (the
4949
index) after them. When the array is mutable, the resulting [memory location]
5050
can be assigned to.

src/expressions/call-expr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
A _call expression_ consists of an expression followed by a parenthesized
1111
expression-list. It invokes a function, providing zero or more input variables.
1212
If the function eventually returns, then the expression completes. For
13-
[non-function types](types.html#function-item-types), the expression f(...) uses
13+
[non-function types](types/function-item.html), the expression f(...) uses
1414
the method on one of the [`std::ops::Fn`], [`std::ops::FnMut`] or
1515
[`std::ops::FnOnce`] traits, which differ in whether they take the type by
1616
reference, mutable reference, or take ownership respectively. An automatic

src/expressions/closure-expr.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ functions, as an abbreviation for defining and capturing a separate function.
2525

2626
Significantly, closure expressions _capture their environment_, which regular
2727
[function definitions] do not. Without the `move` keyword, the closure expression
28-
[infers how it captures each variable from its environment](types.html#capture-modes),
28+
[infers how it captures each variable from its environment](types/closure.html#capture-modes),
2929
preferring to capture by shared reference, effectively borrowing
3030
all outer variables mentioned inside the closure's body. If needed the compiler
3131
will infer that instead mutable references should be taken, or that the values
@@ -35,7 +35,7 @@ prefixing it with the `move` keyword. This is often used to ensure that the
3535
closure's type is `'static`.
3636

3737
The compiler will determine which of the [closure
38-
traits](types.html#call-traits-and-coercions) the closure's type will implement by how it
38+
traits](types/closure.html#call-traits-and-coercions) the closure's type will implement by how it
3939
acts on its captured variables. The closure will also implement
4040
[`Send`](special-types-and-traits.html#send) and/or
4141
[`Sync`](special-types-and-traits.html#sync) if all of its captured types do.
@@ -67,5 +67,5 @@ ten_times(move |j| println!("{}, {}", word, j));
6767

6868
[_Expression_]: expressions.html
6969
[_BlockExpression_]: expressions/block-expr.html
70-
[_TypeNoBounds_]: types.html
70+
[_TypeNoBounds_]: types.html#type-expressions
7171
[_FunctionParameters_]: items/functions.html

src/expressions/loop-expr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ A `loop` expression repeats execution of its body continuously:
3737
`loop { println!("I live."); }`.
3838

3939
A `loop` expression without an associated `break` expression is diverging and
40-
has type [`!`](types.html#never-type). A `loop` expression containing
40+
has type [`!`](types/never.html). A `loop` expression containing
4141
associated [`break` expression(s)](#break-expressions) may terminate, and must
4242
have type compatible with the value of the `break` expression(s).
4343

src/expressions/method-call-expr.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dot, an expression path segment, and a parenthesized expression-list. Method cal
99
resolved to associated [methods] on specific traits, either statically
1010
dispatching to a method if the exact `self`-type of the left-hand-side is known,
1111
or dynamically dispatching if the left-hand-side expression is an indirect
12-
[trait object](types.html#trait-objects).
12+
[trait object](types/trait-object.html).
1313

1414
```rust
1515
let pi: Result<f32, _> = "3.14".parse();
@@ -101,8 +101,8 @@ method and you'll be fine.
101101
[_Expression_]: expressions.html
102102
[_PathExprSegment_]: paths.html#paths-in-expressions
103103
[visible]: visibility-and-privacy.html
104-
[array]: types.html#array-and-slice-types
105-
[trait objects]: types.html#trait-objects
104+
[array]: types/array.html
105+
[trait objects]: types/trait-object.html
106106
[disambiguate call]: expressions/call-expr.html#disambiguating-function-calls
107107
[disambiguating function call syntax]: expressions/call-expr.html#disambiguating-function-calls
108108
[dereference]: expressions/operator-expr.html#the-dereference-operator

0 commit comments

Comments
 (0)