glad to see 'implicit' conversions are now explicit as of rust 1.66.1

This commit is contained in:
Vincent Batts 2023-01-14 20:57:36 -05:00
parent 45a76f19ff
commit 773b9cbafb
42 changed files with 11 additions and 12 deletions

View file

@ -1,13 +1,14 @@
fn main() {
println!("coin toss: {}", pick_one("heads", "tails"));
println!("cash prize: {}", pick_one(500, 1000));
println!("cash prize: {}", pick_one(5.0, 1000));
}
let a: [i32; 3] = [1, 2, 3];
let x: i8 = 15;
let y: i16 = 1000;
fn pick_one<T>(a: T, b: T) -> T {
if std::process::id() % 2 == 0 {
return a
} else {
return b
for i in 0..3 {
println!("a[{i}]: {}", a[i]);
println!("a[{i}] * x * y = {}", multiply(a[i], x.into(), y.into()));
}
}
fn multiply(a: i32, x: i32, y: i32) -> i32 {
return a * x * y;
}