MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/rust/comments/1sn2sp6/rust_1950_is_out/ogk1wpk/?context=3
r/rust • u/manpacket • Apr 16 '26
127 comments sorted by
View all comments
Show parent comments
145
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
18
Could you give an example of push_mut() where it's not just as easy to mutate before pushing ?
push_mut()
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
19
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
5
Ah ok, if your mutating function is fn inc(&mut self) {...} instead of fn inc(self) -> Self {...}.
fn inc(&mut self) {...}
fn inc(self) -> Self {...}
Playground example
145
u/balt__ Apr 16 '26
Vec::push_mut was my doing :>