Accesses the [`FastVec`] mutably as a [`Vec`]. # Safety If `f` panics the [`Vec`] must be unmodified.
(&mut self, f: impl FnOnce(&mut Vec<T>))
| 112 | /// # Safety |
| 113 | /// If `f` panics the [`Vec`] must be unmodified. |
| 114 | unsafe fn mut_vec(&mut self, f: impl FnOnce(&mut Vec<T>)) { |
| 115 | let copied = std::ptr::read(self as *mut FastVec<T>); |
| 116 | let mut vec = ManuallyDrop::new(Vec::from(copied)); |
| 117 | f(&mut vec); |
| 118 | let copied = FastVec::from(ManuallyDrop::into_inner(vec)); |
| 119 | std::ptr::write(self as *mut FastVec<T>, copied); |
| 120 | } |
| 121 | |
| 122 | /// Get a pointer to write to without incrementing length. |
| 123 | #[inline(always)] |