Skip to main content

Counters

Struct Counters 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

Returns how many points the table holds, numbered or not.

Source

pub fn is_empty(&self) -> bool

Returns whether the table holds no point at all.

Source

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.

Source

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.

Source

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, its ref=, see lists) 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).

Source

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 Debug for Counters

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Counters

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl SingletonTable for Counters

Source§

const NAME: &'static str = "flm.counters"

The name of the one table that uses this value type.
Source§

fn table_name() -> TableName<Self>
where Self: Sized,

The typed table key (TableName) of that one table.
Source§

impl Table for Counters

Source§

fn absorb(&mut self, piece: Counters)

Combines piece, a table piece produced by the same stage, into self. Read more
Source§

fn project(&self, cx: &dyn ProjectCx) -> SerialValue

Serializes the table as plain data, for the inspection dumps (crate::dump) and tests. Read more
Source§

fn piece_class(&self) -> PieceClass

Classifies self, taken as a table piece: see PieceClass. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Counters

§

impl !UnwindSafe for Counters

§

impl Forget for Counters

§

impl Freeze for Counters

§

impl Move for Counters

§

impl Send for Counters
where 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 Counters
where 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 Counters

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.