pub struct Counters { /* private fields */ }Expand description
The counter table, flm.counters: every reference point the numbering
stage read, each with its record (CounterRecord) or with nothing for a
point that is not numbered.
A point that the table does not hold at all is a point the stage never
read, such as a point inside a synthesized value, which is not part of the
document; this differs from a point the stage read and did not number.
Counters::lookup tells the two apart, as
Anchors::lookup does
for anchors.
The table also carries the compiled counter styles and within-joiners with
which the numbers are written (the counter styles in the records, the
within-joiners per counter), so that a lowering rule writes a number from
the table alone, without the registry. It also carries every counter style
the registry declares, compiled, with the host’s replacements applied,
whether or not a record of this document uses it: Counters::style
returns one by name, so that a rule may show a point’s number in a declared
counter style other than its record’s, through
Counters::format_in_style.
The numbering stage builds the table with Counters::insert,
Counters::number_within and Counters::number_nested; a caller that
builds a table of its own, for instance in a test, uses the same methods.
Implementations§
Source§impl Counters
impl Counters
Sourcepub fn insert(&mut self, point: PointId, record: Option<CounterRecord>)
pub fn insert(&mut self, point: PointId, record: Option<CounterRecord>)
Records record for point; None records that the point was read
and not numbered. A record already held for point is replaced.
Sourcepub fn number_within(
&mut self,
counter: impl Into<Name>,
joiner: Arc<dyn CompiledWithinJoiner>,
)
pub fn number_within( &mut self, counter: impl Into<Name>, joiner: Arc<dyn CompiledWithinJoiner>, )
Records joiner as the within-joiner that writes counter‘s ancestors’
numbers before its number.
Sourcepub fn number_nested(
&mut self,
counter: impl Into<Name>,
joiner: Arc<dyn CompiledWithinJoiner>,
)
pub fn number_nested( &mut self, counter: impl Into<Name>, joiner: Arc<dyn CompiledWithinJoiner>, )
Records joiner as the nesting joiner of counter, which writes the
enclosing instance’s number before the number of a point of a nested
scoped instance of counter.
Sourcepub fn style(&self, name: &Name) -> Option<&Arc<CounterStyle>>
pub fn style(&self, name: &Name) -> Option<&Arc<CounterStyle>>
Returns the compiled counter style declared under name, or None
when no feature declares a counter style of that name.
Every counter style a feature declares is returned, whether or not a
record of this document uses it, and where the host replaced the
declaration through NumberingConfig, the
result is the replacement. A counter style derived for a point’s own
number template is not declared and is not returned here; the point’s
record holds it (CounterRecord::style).
A lowering rule shows a point’s number in a declared counter style
other than its record’s (for instance a mark written in a counter style
of its own, beside the counter style that references use) by passing
the result to Counters::format_in_style, without the registry. The
counter style must declare at least as many sub-levels as the point’s
value carries, or the writing fails with
FormatError::UndeclaredSubLevel.
A table that the numbering stage did not write (a default value)
carries no counter style and returns None for every name.
Sourcepub fn record(&self, point: PointId) -> Option<&CounterRecord>
pub fn record(&self, point: PointId) -> Option<&CounterRecord>
Returns the record of point, or None both for a point the stage
never read and for one it did not number. A caller that must tell the
two apart calls Counters::lookup.
Sourcepub fn lookup(&self, point: PointId) -> Option<Option<&CounterRecord>>
pub fn lookup(&self, point: PointId) -> Option<Option<&CounterRecord>>
Returns what the table holds for point: None when the stage never
read it, Some(None) when it read it and gave it no number, and
Some(Some(record)) when it numbered it.
Sourcepub fn points(
&self,
) -> impl Iterator<Item = (PointId, Option<&CounterRecord>)> + '_
pub fn points( &self, ) -> impl Iterator<Item = (PointId, Option<&CounterRecord>)> + '_
Returns every point the table holds, in the order of point
identifiers, with its record or None.
Sourcepub fn format(
&self,
point: PointId,
options: &FormatOptions,
) -> Option<Result<Vec<NumberSegment>, FormatError>>
pub fn format( &self, point: PointId, options: &FormatOptions, ) -> Option<Result<Vec<NumberSegment>, FormatError>>
Returns the number of point, written in the counter style its record
holds: None when the table holds no number for the point, and
otherwise the segments of the number, each linking to point or to
nothing.
options says which variant of the prefix words to use, and whether
the word before the number and the delimiters around it are written.
§Errors
FormatError when the record and its counter style do not fit each
other, or when the content could not be built. The numbering stage
refuses a record that its counter style cannot write, so such an error
reveals a fault in the program, not in a document.
Sourcepub fn format_in_style(
&self,
point: PointId,
style: &CounterStyle,
options: &FormatOptions,
) -> Option<Result<Vec<NumberSegment>, FormatError>>
pub fn format_in_style( &self, point: PointId, style: &CounterStyle, options: &FormatOptions, ) -> Option<Result<Vec<NumberSegment>, FormatError>>
Returns the number of point written in style instead of the
counter style its record holds: the recorded value, with style’s
number format, words and delimiters, preceded by the parts of the
counters it is numbered within, each written as the record holds it, in
its own counter style. Returns None when the table holds no number
for the point.
A rule uses it to show a point’s number in another form than the one a
reference to the point shows, without a second record. style is one
of two kinds:
- a counter style derived from the record’s own
(
CounterStyle::with_number_format), which shares the sub-levels, words and number writer the record was checked against. The lists feature writes the label beside a numbered item in this way, through the list’s label template, while the record’s counter style (from the list’s reference template, itsref=, seelists) serves every reference to the item; - a declared counter style, looked up by its name with
Counters::style, for instance for a mark written in a counter style of its own.
§Errors
The same as Counters::format; a style that is not derived from
the record’s own may also declare fewer sub-levels than the value
carries (FormatError::UndeclaredSubLevel).
Sourcepub fn format_many(
&self,
points: &[PointId],
options: &FormatOptions,
) -> Result<ManyNumbers, FormatError>
pub fn format_many( &self, points: &[PointId], options: &FormatOptions, ) -> Result<ManyNumbers, FormatError>
Returns the numbers of several points, written in one group per
counter style: Eqs.~(1–3, 7, and 9) for the points shown in one
counter style, Thm. 1.1 for those of another.
The points are grouped by the counter style they are shown in, each
group keeping the place of its first point, and each group is written
in one call of format_many, with every point’s
own ancestors. The counter style’s number writer
then decides which numbers of a group are written together and which
collapse into a range; the default writer groups the values by the
counters they are numbered within and never writes a range across two
such groups. The groups are returned separately, in
ManyNumbers::groups, and the caller joins them. A point for which
the table holds no number is not written and is listed in
ManyNumbers::unnumbered.
Two points are in one group when their records hold the same compiled
counter style, compared by identity, not merely counter styles of the
same name. In a table
that the numbering stage wrote, a record holds either the compiled
counter style that the registry build made for its counter style’s
name, or, for a point with a number template of its own
(NumberSource::number_format),
the counter style derived from it with that template, which the stage
makes once per template text, counter style and run: the points of one
template are grouped together, and apart from the points written in the
declared counter style.
With no numbered point at all, the result holds no group, and not the counter style’s text for an empty list: with no counter style there is no such text to write.
§Errors
The same as Counters::format.
Trait Implementations§
Source§impl SingletonTable for Counters
impl SingletonTable for Counters
Source§impl Table for Counters
impl Table for Counters
Source§fn project(&self, cx: &dyn ProjectCx) -> SerialValue
fn project(&self, cx: &dyn ProjectCx) -> SerialValue
crate::dump) and tests. Read moreSource§fn piece_class(&self) -> PieceClass
fn piece_class(&self) -> PieceClass
Auto Trait Implementations§
impl !RefUnwindSafe for Counters
impl !UnwindSafe for Counters
impl Forget for Counters
impl Freeze for Counterswhere
*const LeafNode<PointId, Option<CounterRecord>> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(PointId, Option<CounterRecord>)>>: Freeze,
*const LeafNode<Name, Arc<dyn CompiledWithinJoiner>> is !null: Freeze,
PhantomData<Box<(Name, Arc<dyn CompiledWithinJoiner>)>>: Freeze,
*const ArcInner<BTreeMap<Name, Arc<CounterStyle>>> is !null: Freeze,
PhantomData<ArcInner<BTreeMap<Name, Arc<CounterStyle>>>>: Freeze,
impl Move for Counters
impl Send for Counterswhere
NodeRef<Owned, PointId, Option<CounterRecord>, LeafOrInternal>: Send,
BoxRaw<(PointId, Option<CounterRecord>)>: Send,
NodeRef<Owned, Name, Arc<dyn CompiledWithinJoiner>, LeafOrInternal>: Send,
BoxRaw<(Name, Arc<dyn CompiledWithinJoiner>)>: Send,
Arc<BTreeMap<Name, Arc<CounterStyle>>>: Send,
impl Sync for Counterswhere
NodeRef<Owned, PointId, Option<CounterRecord>, LeafOrInternal>: Sync,
BoxRaw<(PointId, Option<CounterRecord>)>: Sync,
NodeRef<Owned, Name, Arc<dyn CompiledWithinJoiner>, LeafOrInternal>: Sync,
BoxRaw<(Name, Arc<dyn CompiledWithinJoiner>)>: Sync,
Arc<BTreeMap<Name, Arc<CounterStyle>>>: Sync,
impl Unpin for Counters
impl UnsafeUnpin for Counterswhere
*const LeafNode<PointId, Option<CounterRecord>> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(PointId, Option<CounterRecord>)>>: UnsafeUnpin,
*const LeafNode<Name, Arc<dyn CompiledWithinJoiner>> is !null: UnsafeUnpin,
PhantomData<Box<(Name, Arc<dyn CompiledWithinJoiner>)>>: UnsafeUnpin,
*const ArcInner<BTreeMap<Name, Arc<CounterStyle>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<BTreeMap<Name, Arc<CounterStyle>>>>: UnsafeUnpin,
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> 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