mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-15 01:52:42 +00:00
25 lines
614 B
Rust
25 lines
614 B
Rust
// ./src/types/inference.md
|
|
|
|
|
|
fn part0() {
|
|
// Because of the annotation, the compiler knows that `elem` has type u8.
|
|
let elem = 5u8;
|
|
|
|
// Create an empty vector (a growable array).
|
|
let mut vec = Vec::new();
|
|
// At this point the compiler doesn't know the exact type of `vec`, it
|
|
// just knows that it's a vector of something (`Vec<_>`).
|
|
|
|
// Insert `elem` in the vector.
|
|
vec.push(elem);
|
|
// Aha! Now the compiler knows that `vec` is a vector of `u8`s (`Vec<u8>`)
|
|
// TODO ^ Try commenting out the `vec.push(elem)` line
|
|
|
|
println!("{:?}", vec);
|
|
}
|
|
|
|
pub fn main() {
|
|
part0();
|
|
}
|
|
|