In C++, I can do in-place assignments that increment the variable var
while printing it out to the screen:
int var = 5;
std::cout << ( var += 1 ) << std::endl;
I am doing this because Rust does not have the in/decrement operators ++
& --
. I tried it in Rust:
let mut counter = 0;
println!("{}", (counter += 1));
It is saying:
error[E0277]: the trait bound `(): std::fmt::Display` is not satisfied
--> src/main.rs:3:20
|
3 | println!("{}", (counter += 1));
| ^^^^^^^^^^^^^^ the trait `std::fmt::Display` is not implemented for `()`
|
= note: `()` cannot be formatted with the default formatter; try using `:?` instead if you are using a format string
= note: required by `std::fmt::Display::fmt`