use stable_vec::StableVec;
struct EchoDrop(pub char);
impl Drop for EchoDrop {
fn drop(&mut self) {
println!("I was dropped: {}", self.0);
}
}
fn main() {
let mut sv = StableVec::new();
sv.push(EchoDrop('a'));
let b_idx = sv.push(EchoDrop('b'));
sv.push(EchoDrop('c'));
{
println!("--- removing 'b' (nothing should be dropped!) ...");
let _b = sv.remove(b_idx);
println!("--- letting 'b' go out of scope (it should be dropped now!) ...");
}
println!("--- Letting 'sv' go out of scope (it should drop 'a' and 'c'!) ...");
}