-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Inferred Types and Type Parameters to their own pages.
- Loading branch information
Showing
8 changed files
with
48 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Inferred type | ||
|
||
> **<sup>Syntax</sup>**\ | ||
> _InferredType_ : `_` | ||
The inferred type asks the compiler to infer the type if possible based on the | ||
surrounding information available. It cannot be used in item signatures. It is | ||
often used in generic arguments: | ||
|
||
```rust | ||
let x: Vec<_> = (0..10).collect(); | ||
``` | ||
|
||
<!-- | ||
What else should be said here? | ||
The only documentation I am aware of is https://rust-lang-nursery.github.io/rustc-guide/type-inference.html | ||
There should be a broader discussion of type inference somewhere. | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Type parameters | ||
|
||
Within the body of an item that has type parameter declarations, the names of | ||
its type parameters are types: | ||
|
||
```rust | ||
fn to_vec<A: Clone>(xs: &[A]) -> Vec<A> { | ||
if xs.is_empty() { | ||
return vec![]; | ||
} | ||
let first: A = xs[0].clone(); | ||
let mut rest: Vec<A> = to_vec(&xs[1..]); | ||
rest.insert(0, first); | ||
rest | ||
} | ||
``` | ||
|
||
Here, `first` has type `A`, referring to `to_vec`'s `A` type parameter; and | ||
`rest` has type `Vec<A>`, a vector with element type `A`. |