The standard way to increment is with
ss += 1;.
Rust doesn't provide a
++ operator for two primary reasons:
- The primary motivator for
++ is for C-style
for(init;condition;increment) loops, which aren't present at all in Rust. Instead, you use
for pattern in iterator, so there's no need to manually increment your iterator cursor.
- The ordering rules around
++ as an expression are nonobvious, even for experienced developers. On the other hand,
+= is a statement with always clear ordering, and barely longer than
++ as a statement.
Language lawyer minutia and pedantry below.
: Well, in actuality,
+= isn't a statement.
place += value is an expression returning
() ("unit", the type with only one value, the empty tuple). As far as I'm aware, there's only one actual statement in Rust:
let. Even assignment is just a
: And there's experimental work that makes even that not true, allowing the use of
let as an expression (in some restricted contexts).