You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-07-13 01:30:59 +02:00
23 lines
312 B
Markdown
23 lines
312 B
Markdown
![]() |
# Type Inference
|
||
|
|
||
|
Rust will look at how the variable is _used_ to determine the type:
|
||
|
|
||
|
```rust,editable
|
||
|
fn takes_u32(x: u32) {
|
||
|
println!("u32: {x}");
|
||
|
}
|
||
|
|
||
|
fn takes_i8(y: i8) {
|
||
|
println!("i8: {y}");
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let x = 10;
|
||
|
let y = 20;
|
||
|
|
||
|
takes_u32(x);
|
||
|
takes_i8(y);
|
||
|
// takes_u32(y);
|
||
|
}
|
||
|
```
|