pub struct CounterValue { /* private fields */ }Expand description
A counter value: the value a counter has at one numbered reference point, a number with optional sub-numbers under it.
A sub-number is a further level of counting under the number: the value
(3, 2) is the second sub-numbered item under the number three, shown as
3b by a counter style whose first sub-level is written in letters
(SubLevelDecl). A value always has a number, and
it has a sub-number for every deeper level at which the counter was
advanced.
Values are ordered by their components: the number first, then each sub-number in turn, a value without a given sub-number coming before the same value with one. The default number writer sorts several values in this order before it writes them, and collapses values that immediately succeed one another into a range.
§Examples
use flm_core::stdlib::features::numbering::CounterValue;
let third = CounterValue::new(3);
assert_eq!(third.number(), 3);
assert!(third.sub_numbers().is_empty());
let second_under_third = CounterValue::with_sub_numbers(3, [2]);
assert_eq!(second_under_third.components(), [3, 2]);
assert!(second_under_third.immediately_succeeds(&CounterValue::with_sub_numbers(3, [1])));Implementations§
Source§impl CounterValue
impl CounterValue
Sourcepub fn new(number: i64) -> CounterValue
pub fn new(number: i64) -> CounterValue
Returns the value number, with no sub-number.
Sourcepub fn with_sub_numbers(
number: i64,
sub_numbers: impl IntoIterator<Item = i64>,
) -> CounterValue
pub fn with_sub_numbers( number: i64, sub_numbers: impl IntoIterator<Item = i64>, ) -> CounterValue
Returns the value number with the given sub-numbers, outermost first.
Sourcepub fn sub_numbers(&self) -> &[i64]
pub fn sub_numbers(&self) -> &[i64]
Returns the sub-numbers, outermost first; empty for a value that has none.
Sourcepub fn components(&self) -> &[i64]
pub fn components(&self) -> &[i64]
Returns the value’s components: the number followed by the sub-numbers, in the order they are written. Never empty.
Sourcepub fn immediately_succeeds(&self, other: &CounterValue) -> bool
pub fn immediately_succeeds(&self, other: &CounterValue) -> bool
Returns whether this value comes immediately after other: the two
have the same number of components, all components but the last are
equal, and the last is one more.
The default number writer builds runs of consecutive values with this
test, so (3, 4) immediately succeeds (3, 3), while 4 does not
immediately succeed (3, 9): values of different depths are never
consecutive.
Sourcepub fn advanced(&self, level: usize) -> CounterValue
pub fn advanced(&self, level: usize) -> CounterValue
Returns this value advanced at level: level 0 is the number, level 1
the first sub-number, and so on. The advanced level gains one, every
deeper level returns to zero, and a level the value does not have yet
is created, together with the levels between, which are created at
zero.
Advancing is the only operation that moves a counter on, and creating a
deeper level is part of it: a reference point that starts a
sub-numbered group advances the number and then the first sub-number,
which takes 3 to (3, 1).
A level that already has the largest number a value can hold
(i64::MAX) keeps it instead of wrapping round to the smallest. No
document reaches it, since every level counts points one by one.
The caller is responsible for bounding level: a value holds every
level up to the one advanced, so advancing at a level far deeper than
the value’s own depth takes memory in proportion to that level. A
counter style declares how many sub-numbers it can write, and the
numbering stage refuses a point that would advance a level deeper than
that before it advances anything; this bounds the work in the library.
§Examples
use flm_core::stdlib::features::numbering::CounterValue;
let value = CounterValue::with_sub_numbers(3, [2, 1]);
assert_eq!(value.advanced(1).components(), [3, 3, 0]);
assert_eq!(value.advanced(0).components(), [4, 0, 0]);
assert_eq!(CounterValue::new(3).advanced(1).components(), [3, 1]);Trait Implementations§
Source§impl Clone for CounterValue
impl Clone for CounterValue
Source§impl Debug for CounterValue
impl Debug for CounterValue
impl Eq for CounterValue
Source§impl Hash for CounterValue
impl Hash for CounterValue
Source§impl Ord for CounterValue
impl Ord for CounterValue
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for CounterValue
impl PartialEq for CounterValue
Source§impl PartialOrd for CounterValue
impl PartialOrd for CounterValue
impl StructuralPartialEq for CounterValue
Auto Trait Implementations§
impl Forget for CounterValue
impl Freeze for CounterValue
impl Move for CounterValue
impl RefUnwindSafe for CounterValue
impl Send for CounterValuewhere
RawVecInner: Send,
impl Sync for CounterValuewhere
RawVecInner: Sync,
impl Unpin for CounterValue
impl UnsafeUnpin for CounterValue
impl UnwindSafe for CounterValuewhere
RawVecInner: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more