Does Rust have a short-circuiting AndAssign
(OrAssign
) operator &&=
(||=
), or something similar, for bool
? These would desugar into:
// x &&= y
if x { x = y; }
// x ||= y
if !x { x = y; }
Is there a shorter way to write these out, or is the longhand the only way?
As of writing, there are no compound assignment operations for boolean AND or OR.
Note however that
if x { x = y; }
can be shortened tox = x && y
- same with||
.