How to assign multiple values to multiple variables in one line with Rust

2 Answers

0 votes
fn main() {
    let (a, b, c, d) = (8, 4, 90, 101);
    
    println!("{} {} {} {}", a, b, c, d);
}

  
    
/*
run:
  
8 4 90 101
  
*/

 



answered Oct 6, 2024 by avibootz
0 votes
fn print_type_of<T>(_: &T) {
    println!("{}", std::any::type_name::<T>());
}

fn main() {
    let (a, b, c, d) = (1, "Rust", 3.14, -309801);
    
    println!("{} {} {} {}", a, b, c, d);
    
    print_type_of(&a);
    print_type_of(&b);
    print_type_of(&c);
    print_type_of(&d);
}

   
     
/*
run:

1 Rust 3.14 -309801
i32
&str
f64
i32
   
*/
  
 

 



answered Jul 14, 2025 by avibootz
edited Jul 14, 2025 by avibootz
...