Can `Pin` container replace/remove elements safely
⚓ Rust 📅 2026-04-06 👤 surdeus 👁️ 6I've implemented a custom PinVec, which is a Vec with pinned element. I'm trying to figure out if the following get/set interface is sounded.
struct PinVec<T> { ... }
impl<T> PinVec<T> {
fn get(&self, idx: usize) -> Pin<&T> { .. }
fn get_mut(&mut self, idx: usize) -> Pin<&mut T> { .. }
fn push(&mut self, val: T) { .. }
fn set(&mut self, idx: usize, val: T) { .. }
fn remove_last(&mut self) { .. }
}
Particularly, are set and remove_last sound, do they require T: Unpin or unsafe? The relevant part seems to be this Drop Guarantee section std::pin - Rust. Though I don't know if that reads as I can drop old values safely and T will handle notifications by itself.
3 posts - 3 participants
🏷️ Rust_feed