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: u16
Implementations§
Source§impl UnitSet
impl UnitSet
Sourcefn set(self, unit: Unit, is_zero: bool) -> UnitSet
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) 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 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.