In Rust, functions can return multiple values using tuples, and these values can be of different types.

Example Code

fn foo() -> (i32,bool,[i32;5]) {
    
    let a = 5;
    let b = false;
    
    (a,b,[1,2,3]) // Return a tuple
}

fn main(){
    // Access via indexing
    let result = foo();
    println!("{} {} {}",result.0,result.1,result.2[0]);
    // Access via destructuring
    let (a,b,c) = foo();
    println!("{} {} {}",a,b,c[0]);

}

It is recommended to use this method when the number of return values is between 2 and 3. If the number is too large, consider using a struct instead.