Why does BTreeSet use ManuallyDrop?

⚓ Rust    📅 2026-02-01    👤 surdeus    👁️ 11      

surdeus

Warning

This post was published 79 days ago. The information described in this article may have changed.

From set.rs - source

    fn sub(self, rhs: &BTreeSet<T, A>) -> BTreeSet<T, A> {
        BTreeSet::from_sorted_iter(
            self.difference(rhs).cloned(),
            ManuallyDrop::into_inner(self.map.alloc.clone()),
        )
    }

I don't understand what is going on here.

3 posts - 2 participants

Read full topic

🏷️ Rust_feed