Function returning multiple values
-
tuple
-
returns a tuple
fn stats(a: f32, b: f32) -> (f32, f32) {
(a + b, a * b)
}
fn main() {
let (sum, multiple) = stats(4.0, 7.0);
println!("{sum}, {multiple}");
}
11, 28
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
tuple
returns a tuple
fn stats(a: f32, b: f32) -> (f32, f32) {
(a + b, a * b)
}
fn main() {
let (sum, multiple) = stats(4.0, 7.0);
println!("{sum}, {multiple}");
}
11, 28