push_mut/lib.rs
1#![doc = include_str!("../README.md")]
2
3/// An extension trait for `Vec<T>` that provides a [`PushMut::push_mut`] method.
4pub trait PushMut<T> {
5 /// Pushes a value to the back of the vector, and returns a mutable reference to it.
6 fn push_mut(&mut self, value: T) -> &mut T;
7}
8
9impl<T> PushMut<T> for Vec<T> {
10 fn push_mut(&mut self, value: T) -> &mut T {
11 self.push(value);
12 unsafe { self.last_mut().unwrap_unchecked() }
13 }
14}