set_val.rs - source
Description: Source of the Rust file `library/alloc/src/collections/btree/set_val.rs`.

#
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(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, 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}