は、私が画面にそれをプリントアウトしながら、変数var
をインクリメントインプレース割り当てを行うことができます。Rustでインプレースアサインメントを行う方法は? C++で
int var = 5;
std::cout << (var += 1) << std::endl;
錆がで/デクリメント演算子++
& --
を持っていないので、私はこれをやっています。私は錆でそれを試してみました:
let mut counter = 0;
println!("{}", (counter += 1));
それは言っている:
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`