Add better formatting to tuple like {.0} {.1}

so.. this is what i want

let foo:(&str,i32) = ("bar",420);
println!("{.0} dude im {.1}",me);

im very new to rust so is there any other way to do this please say it to me thanks :slight_smile:

Hi and welcome here. This is the “internals” forum; unless you’re proposing that to solve your problem, the language Rust needs to be changed (and I assume that’s indeed not your intention here), questions like this are a better fit for the “users” forum over on users.rust-lang.org.

In any case, let me still answer the question: The way to access the components of the tuple foo is via the expressions foo.0 and foo.1. Using arbitrary expressions in a println! call is possible by using the {} placeholder and providing the corresponding expressions in-order as additional arguments. So to make your code work, just write

let foo: (&str, i32) = ("bar", 420);
println!("{} dude im {}", foo.0, foo.1);
4 Likes

Another way to do this is as follows:

let (a, b): (&str, i32) = ("bar", 420);
println!("{a} dude im {b}");
1 Like