Skip to content

Commit 7166c5f

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 f87f140 commit 7166c5f

Some content is hidden

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

54 files changed

+1011
-905
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/crates-and-source-files.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn main() {
111111
[module]: items/modules.html
112112
[module path]: paths.html
113113
[attributes]: attributes.html
114-
[unit]: types.html#tuple-types
114+
[unit]: types/tuple.html
115115
[_InnerAttribute_]: attributes.html
116116
[_Item_]: items.html
117117
[_shebang_]: https://en.wikipedia.org/wiki/Shebang_(Unix)

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
@@ -277,7 +277,7 @@ exist in `core::ops` and `core::cmp` with the same names.
277277
[let statement]: statements.html#let-statements
278278
[Mutable `static` items]: items/static-items.html#mutable-statics
279279
[const contexts]: const_eval.html
280-
[slice]: types.html#array-and-slice-types
280+
[slice]: types/slice.html
281281
[static variables]: items/static-items.html
282282
[Temporary values]: #temporary-lifetimes
283283
[Variables]: variables.html

src/expressions/array-expr.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
> &nbsp;&nbsp; | `[` [_Expression_] ( `,` [_Expression_] )<sup>\*</sup> `,`<sup>?</sup> `]`\
99
> &nbsp;&nbsp; | `[` [_Expression_] `;` [_Expression_] `]`
1010
11-
An _[array](types.html#array-and-slice-types) expression_ can be written by
11+
An _[array](types/array.html) expression_ can be written by
1212
enclosing zero or more comma-separated expressions of uniform type in square
1313
brackets. This produces and array containing each of these values in the
1414
order they are written.
@@ -36,7 +36,7 @@ greater than 1 then this requires that the type of `a` is
3636
> _IndexExpression_ :\
3737
> &nbsp;&nbsp; [_Expression_] `[` [_Expression_] `]`
3838
39-
[Array and slice](types.html#array-and-slice-types)-typed expressions can be
39+
[Array](types/array.html) and [slice](types/slice.html)-typed expressions can be
4040
indexed by writing a square-bracket-enclosed expression of type `usize` (the
4141
index) after them. When the array is mutable, the resulting [memory location]
4242
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

0 commit comments

Comments
 (0)