Skip to main content

alloc/collections/btree/
set_val.rs

1/// Zero-Sized Type (ZST) for internal `BTreeSet` values.
2/// Used instead of `()` to differentiate between:
3/// * `BTreeMap<T, ()>` (possible user-defined map)
4/// * `BTreeMap<T, SetValZST>` (internal set representation)
5#[derive(#[automatically_derived]
impl ::core::fmt::Debug for SetValZST {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "SetValZST")
    }
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for SetValZST {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialEq for SetValZST {
    #[inline]
    fn eq(&self, other: &SetValZST) -> bool { true }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Ord for SetValZST {
    #[inline]
    fn cmp(&self, other: &SetValZST) -> ::core::cmp::Ordering {
        ::core::cmp::Ordering::Equal
    }
}Ord, #[automatically_derived]
impl ::core::cmp::PartialOrd for SetValZST {
    #[inline]
    fn partial_cmp(&self, other: &SetValZST)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::option::Option::Some(::core::cmp::Ordering::Equal)
    }
}PartialOrd, #[automatically_derived]
impl ::core::hash::Hash for SetValZST {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
}Hash, #[automatically_derived]
impl ::core::clone::Clone for SetValZST {
    #[inline]
    fn clone(&self) -> SetValZST { SetValZST }
}Clone, #[automatically_derived]
impl ::core::default::Default for SetValZST {
    #[inline]
    fn default() -> SetValZST { SetValZST {} }
}Default)]
6pub(super) struct SetValZST;
7
8/// A trait to differentiate between `BTreeMap` and `BTreeSet` values.
9/// Returns `true` only for type `SetValZST`, `false` for all other types (blanket implementation).
10/// `TypeId` requires a `'static` lifetime, use of this trait avoids that restriction.
11///
12/// [`TypeId`]: core::any::TypeId
13pub(super) trait IsSetVal {
14    fn is_set_val() -> bool;
15}
16
17// Blanket implementation
18impl<V> IsSetVal for V {
19    default fn is_set_val() -> bool {
20        false
21    }
22}
23
24// Specialization
25impl IsSetVal for SetValZST {
26    fn is_set_val() -> bool {
27        true
28    }
29}