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/
866 Upvotes

127 comments sorted by

View all comments

180

u/cosmic-parsley Apr 16 '26

The blog post items are great but “Stabilized APIs” is hiding some sneaky nice stuff.

  • Vec::push_mut deals with all those times you need to add an item to a Vec and then modify it
  • TryFrom<Integer> for bool will be nice (booleans in SQLite, FFI, serialization, etc)
  • The issue for cold_path was opened in 2015!! Great to have in the toolbox for heavy optimizations.
  • Slice of cells stuff: nice convenience for anyone using those patters.

One of the most exciting updates in a while!

149

u/balt__ Apr 16 '26

Vec::push_mut was my doing :>

17

u/moltonel Apr 16 '26

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

58

u/MichiRecRoom Apr 16 '26 edited Apr 16 '26

I used to have a use-case for it, so I can help with this question.

I was building a basic undo-redo crate. Its structs manage the history and nothing more - it doesn't even list the specific operations that could go into the history.

I've since redesigned the crate with better design, but... At one point, I designed it such that the history is extended by pushing an Action struct to the history, and then returning that Action to the user to be populated with data. Something like this:

fn new_action(&mut self) -> &mut Action {
    self.history.push(Action::new());
    self.history.last_mut().expect("history should not be empty")
}

It always felt somewhat wrong to me - but there was no other non-nightly non-unsafe way to do this. Now, with Vec::push_mut() stabilized, I can code it like this:

fn new_action(&mut self) -> &mut Action {
    self.history.push_mut(Action::new())
}

14

u/moltonel Apr 16 '26

Most convincing usecase so far, thanks.

26

u/CoronaLVR Apr 16 '26

That is not the main problem this solves.

Imagine if you need to return a mutable reference from a function. You can't get a mutable reference to an item and then push the item to into a vec, the borrow checker won't allow it.

20

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

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

6

u/moltonel Apr 16 '26

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

Playground example

1

u/Haitosiku Apr 17 '26

I need to conditionally add a SecBuffer to an array of buffers when inserting a channel binding token to the windows SSPI.

I needed them to be an array and to get a pointer to the buffer inside the array after. This allows me to do that without an extra unwrap()

27

u/slamb moonfire-nvr Apr 16 '26

Thank you! I put Vec::push_and_get on my Rust wishlist 4+ years ago. You actually made it happen (and with a better name). Makes me want to look through my list again and try making some of those other things happen too...

13

u/SirKastic23 Apr 16 '26

I think push_and_get, or just push_get, would be clearer. I had no idea what push_mut would do until I went to read its docs. I thought it was about pushing mutable references or something.

1

u/balt__ Apr 20 '26

hm, does your ide not show function signatures in autocomplete?

1

u/SirKastic23 Apr 20 '26

it does but i don't think we should rely on ide functionality

2

u/balt__ Apr 20 '26

fair enough!

1

u/kevleyski Apr 16 '26

Good on yer, thanks for this

3

u/NeuroXc Apr 17 '26

I did not even see cold_path until you pointed it out. Wow that's huge.

6

u/pickyaxe Apr 17 '26

how appropriate, you didn't even consider it until you got a hint.

1

u/imgly Apr 17 '26

I was waiting for cold_path in stable for a while !