pub(crate) struct UnitSet(u16);Expand description
A bit set that keeps track of all non-zero units on a Span.
Because of alignment, adding this to a Span does not make it any bigger.
The benefit of this bit set is to make it extremely cheap to enable fast
paths in various places. For example, doing arithmetic on a Date with an
arbitrary Span is pretty involved. But if you know the Span only
consists of non-zero units of days (and zero for all other units), then you
can take a much cheaper path.
Tuple Fields§
§0: u16Implementations§
Source§impl UnitSet
impl UnitSet
Sourceconst fn set(self, unit: Unit, is_zero: bool) -> UnitSet
const fn set(self, unit: Unit, is_zero: bool) -> UnitSet
Set the given unit to is_zero status in this set.
When is_zero is false, the unit is added to this set. Otherwise,
the unit is removed from this set.
Sourcepub(crate) const fn from_slice(units: &[Unit]) -> UnitSet
pub(crate) const fn from_slice(units: &[Unit]) -> UnitSet
Returns the set constructed from the given slice of units.
Sourcepub(crate) fn contains(self, unit: Unit) -> bool
pub(crate) fn contains(self, unit: Unit) -> bool
Returns true when this Span contains a non-zero value for the given
unit.
Sourcepub(crate) fn contains_only(self, unit: Unit) -> bool
pub(crate) fn contains_only(self, unit: Unit) -> bool
Returns true if and only if this Span contains precisely one
non-zero unit corresponding to the unit given.
Sourcepub(crate) fn only_calendar(self) -> UnitSet
pub(crate) fn only_calendar(self) -> UnitSet
Returns this set, but with only calendar units.
Sourcepub(crate) fn intersection(self, other: UnitSet) -> UnitSet
pub(crate) fn intersection(self, other: UnitSet) -> UnitSet
Returns the intersection of this set and the one given.
Sourcepub(crate) fn largest_unit(self) -> Option<Unit>
pub(crate) fn largest_unit(self) -> Option<Unit>
Returns the largest unit in this set, or None if none are present.