inferring types
This commit is contained in:
parent
baec55b750
commit
70ca7bb74d
23 changed files with 12 additions and 37 deletions
49
src/main.rs
49
src/main.rs
|
@ -1,40 +1,15 @@
|
|||
// TODO
|
||||
#![allow(unused_variables, dead_code)]
|
||||
|
||||
fn interesting() -> i32 {
|
||||
// this code compiles and doesn't complain about being unused or not returning the correct
|
||||
// thing, but will hit a runtime error if/when this is called
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn transpose(matrix: [[i32; 3]; 3]) -> [[i32; 3]; 3] {
|
||||
let matrix_new = [
|
||||
[matrix[0][0], matrix[1][0], matrix[2][0]], // newline
|
||||
[matrix[0][1], matrix[1][1], matrix[2][1]],
|
||||
[matrix[0][2], matrix[1][2], matrix[2][2]],
|
||||
];
|
||||
return matrix_new;
|
||||
}
|
||||
|
||||
fn pretty_print(matrix: &[[i32; 3]; 3]) {
|
||||
println!("[");
|
||||
for row in matrix {
|
||||
println!(" [ {} {} {} ]", row[0], row[1], row[2]);
|
||||
}
|
||||
println!("]");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let matrix = [
|
||||
[101, 102, 103], // we want the newline here
|
||||
[201, 202, 203],
|
||||
[301, 302, 303],
|
||||
];
|
||||
let x = 10;
|
||||
let y = 20;
|
||||
|
||||
println!("matrix:");
|
||||
pretty_print(&matrix);
|
||||
|
||||
let transposed = transpose(matrix);
|
||||
println!("transposed:");
|
||||
pretty_print(&transposed);
|
||||
takes_u32(x);
|
||||
takes_i8(y);
|
||||
}
|
||||
|
||||
fn takes_u32(x: u32) -> () {
|
||||
println!("{x}");
|
||||
}
|
||||
|
||||
fn takes_i8(x: i8) -> () {
|
||||
println!("{x}");
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue