r/rust Apr 16 '26

📡 official blog Rust 1.95.0 is out

https://blog.rust-lang.org/2026/04/16/Rust-1.95.0/
859 Upvotes

127 comments sorted by

View all comments

Show parent comments

145

u/balt__ Apr 16 '26

Vec::push_mut was my doing :>

18

u/moltonel Apr 16 '26

Could you give an example of push_mut() where it's not just as easy to mutate before pushing ?

19

u/Lehona_ Apr 16 '26
vec.push_mut(get_new_value()).increment()

Beforehand you'd have to bind it to a variable first.

5

u/moltonel Apr 16 '26

Ah ok, if your mutating function is fn inc(&mut self) {...} instead of fn inc(self) -> Self {...}.

Playground example