Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
rtoway
· 5y ago · 0 comments
In Rust, many times this kind of code will compile to the same code using plain old loops and if statements
Comments
[–]
mastax
5y ago
Yes, however for this specific situation `replace()` is not an iterator adapter but a method of `str` which returns a newly allocated `String`. In practice, the compiler does not do something smarter than that:
https://rust.godbolt.org/z/z573Mvjzz
[–]
rtoway
OP
5y ago
Ah you are right about that. Yes, it would be a nice place to avoid an allocation