Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

How to create tuple with different types in Rust

3 Answers

0 votes
fn main() {
    let tuple = (100u8, 200u16, 300u32, 400u64,
                -100i8, -200i16, -300i32, -400i64,
                3.14f32, 19.873f64,
                'z', true);

    println!("tuple = {:?}", tuple);
    
    println!("tuple.0 = {}", tuple.0);
    println!("tuple.1 = {}", tuple.1);
    println!("tuple.2 = {}", tuple.2);
}





/*
run:

tuple = (100, 200, 300, 400, -100, -200, -300, -400, 3.14, 19.873, 'z', true)
tuple.0 = 100
tuple.1 = 200
tuple.2 = 300

*/

 



answered May 3, 2023 by avibootz
0 votes
fn main() {
    let tuple = (17, "rust", 3.14, -9);

    println!("tuple = {:?}", tuple);
    
    println!("tuple.0 = {}", tuple.0);
    println!("tuple.1 = {}", tuple.1);
    println!("tuple.2 = {}", tuple.2);
    println!("tuple.3 = {}", tuple.3);
}





/*
run:

tuple = (17, "rust", 3.14, -9)
tuple.0 = 17
tuple.1 = rust
tuple.2 = 3.14
tuple.3 = -9

*/

 



answered May 3, 2023 by avibootz
edited May 3, 2023 by avibootz
0 votes
fn main() {
    let tuple: (&str, u8, f32) = ("rust", 234, 3.14);

    println!("tuple = {:?}", tuple);
    
    println!("tuple.0 = {}", tuple.0);
    println!("tuple.1 = {}", tuple.1);
    println!("tuple.2 = {}", tuple.2);
}





/*
run:

tuple = ("rust", 234, 3.14)
tuple.0 = rust
tuple.1 = 234
tuple.2 = 3.14

*/

 



answered May 3, 2023 by avibootz
edited May 3, 2023 by avibootz

Related questions

2 answers 155 views
2 answers 111 views
111 views asked May 3, 2023 by avibootz
1 answer 76 views
76 views asked May 3, 2023 by avibootz
1 answer 100 views
1 answer 100 views
1 answer 92 views
...