Why is BTreeSet defined this way?
⚓ Rust 📅 2026-01-27 👤 surdeus 👁️ 2Something I don't understand ( there is so much I don't understand )...
BTreeSet is defined like this:
pub struct BTreeSet<
T,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global,
> {
map: BTreeMap<T, SetValZST, A>,
}
https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#78-81
SetValZST is defined here:
where it explains:
/// Zero-Sized Type (ZST) for internal `BTreeSet` values.
/// Used instead of `()` to differentiate between:
/// * `BTreeMap<T, ()>` (possible user-defined map)
/// * `BTreeMap<T, SetValZST>` (internal set representation)
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Default)]
pub(super) struct SetValZST;
But isn't the definition (of map) private? Does it somehow "leak" even though it is private?
6 posts - 2 participants
🏷️ Rust_feed