4 ms·
Technically Rust calls functions on the variable being printed. Those are defined as "{}" uses the fmt::Display trait and "{:?}" uses the fmt::Debug trait.
by bluejekyll 5y ago
Technically Rust calls functions on the variable being printed. Those are defined as "{}" uses the fmt::Display trait and "{:?}" uses the fmt::Debug trait.
- nine_k 5y agoOh. I wonder if the Display trait implementation can be enforced to have no side effects (beside allocation).
- sidit77 5y agoWhen implementing Display you only get access to an immutable reference to self, so the only possibly side effects are writes to global variables.
- bluejekyll 5y agoThat depends on what Self contains. Using the Cell types and some of the other inner mutating types, it is possible to change the interior state of self even behind a shared reference. Additionally, with unsafe it’s also possible. This is in response to “the only possible” statement. Of course, doing so is not advisable.