Skip to navigation
Return multiple values of different types in rust
20.09.23
You can have a function that returns multiple values of different types. You have many options, but returning a tuple is the easiest. ```rust fn main() { let (maths, english, science, sanskrit) = tuple_func(); println!("Marks obtained in Maths: {maths}"); println!("Marks obtained in English: {english}"); println!("Marks obtained in Science: {science}"); println!("Marks obtained in Sanskrit: {sanskrit}"); } fn tuple_func() -> (f64, f64, f64, f64) { // return marks for a student let maths = 84.50; let english = 85.00; let science = 75.00; let sanskrit = 67.25; (maths, english, science, sanskrit) } ```
https://itsfoss.com/rust-functions/
Reply
Anonymous
Information Epoch 1732398259
When in doubt, use brute force.
Home
Notebook
Contact us