Skip to main content

CounterDecl

Struct CounterDecl 

Source
pub struct CounterDecl {
    pub name: Name,
    pub docs: String,
    pub default_style: Name,
    pub within: Option<Within>,
    pub nesting: Option<WithinJoinerSpec>,
}
Expand description

A counter, as the feature that declares it contributes it to the service slot COUNTERS_SLOT.

A counter is a dotted name under which things are counted in document order, declared by a feature together with the counter it is numbered within; its value at a reference point is a number with optional sub-numbers (CounterValue). The declaration gives the counter’s name, the counter style its numbers are shown in by default, the counter it is numbered within (Within), and the counter’s nesting joiner (nesting). The concepts overview presents counters and counter styles together (counters and counter styles).

The numbering feature numbers every reference point whose number source (NumberSource) gives a declared counter. The feature that owns the point decides whether the point gives a number source (the numbering depth of the headings feature, the switch for numbered equations of the mathematics feature); the numbering feature has no switch of its own.

A counter’s name is dotted and owned by the feature that declares it, like every name the library registers: flm.headings.section, flm.math.equation, and a name under a prefix of its own for a counter that a third party declares. One feature declares a counter, and a name is declared once per registry; the points of any feature may count in it, and points of several kinds that count in one counter form one sequence. A counter style’s name is dotted and owned in the same way (flm.math.style.equation) and is separate from the counter’s name, because two features may each declare a counter style for the same counter.

§Examples

use flm_core::stdlib::features::numbering::{CounterDecl, Within};

// Theorems count from one in every section, and are shown `2.13`.
let decl = CounterDecl::new("example.theorem", "example.style.theorem")
    .docs("The theorems of the document.")
    .within(Within::parent("flm.headings.section"));
assert!(decl.within.is_some());

Fields§

§name: Name

The counter’s name, dotted and owned by the declaring feature, such as flm.headings.section or flm.math.equation. Two declarations of one name fail the registry build, and so does a name beginning with RESERVED_PREFIX.

§docs: String

One sentence saying what the counter counts. The numbering feature keeps it with the declaration and does not display it.

§default_style: Name

The name of the counter style in which a point’s number is shown when the point’s number source gives no other. It is also the counter style in which this counter’s number is written as an ancestor until a point advances the counter. A counter style no feature declares fails the registry build.

§within: Option<Within>

The counter within which this counter is numbered, or None for a counter numbered within nothing, which is never restarted.

§nesting: Option<WithinJoinerSpec>

The counter’s nesting joiner: what a point that counts in a nested scoped instance of this counter writes of the enclosing instance’s number before its own, or None for WithinJoinerSpec::Bare, which writes nothing of it.

A scoped instance is an independent sequence of the counter’s values attached to an enclosing node (NumberSource::instances). An instance inside another is numbered within the enclosing instance’s current value, which the records of its points carry as their last ancestor. The nesting joiner writes that ancestor, in any of the four forms a Within may take: Joined(".") and Template("#{_parent}.") both write 2.(b) for the second item of a list nested in the second item of another list whose items are written 1, 2, and the default writes (b). The ancestor is written in its own counter style, so where the enclosing items are written 1., 2., Template("#{_parent}") writes 2.(b). In a within template, #{_parent} and the counter’s own name both refer to the enclosing instance.

The nesting joiner is compiled when the registry is built, as the counter’s within is. It may write only counters that are ancestors of a nested point under every chain of counters the counter may be numbered within, that is, the counter itself and the counters it is numbered within; any other counter fails the registry build.

Implementations§

Source§

impl CounterDecl

Source

pub fn new(name: impl Into<Name>, default_style: impl Into<Name>) -> CounterDecl

Returns a counter named name, shown in the counter style default_style, numbered within nothing, with no nesting joiner and an empty description.

Source

pub fn docs(self, docs: impl Into<String>) -> CounterDecl

Builder: sets the sentence that says what the counter counts (docs). Without the cargo feature docs, the text is dropped and the field stays empty.

Source

pub fn within(self, within: Within) -> CounterDecl

Builder: sets the counter within which this counter is numbered (within).

Source

pub fn nesting(self, joiner: WithinJoinerSpec) -> CounterDecl

Builder: sets the nesting joiner, what a point of a nested scoped instance writes of the enclosing instance’s number (nesting).

Trait Implementations§

Source§

impl Clone for CounterDecl

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CounterDecl

Source§

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

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

impl Eq for CounterDecl

Source§

impl Hash for CounterDecl

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CounterDecl

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CounterDecl

Auto Trait Implementations§

§

impl Forget for CounterDecl

§

impl Freeze for CounterDecl
where *const ArcInner<str> is !null: Freeze, PhantomData<ArcInner<str>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<Name>: Freeze,

§

impl Move for CounterDecl

§

impl RefUnwindSafe for CounterDecl

§

impl Send for CounterDecl
where Arc<str>: Send, RawVecInner: Send,

§

impl Sync for CounterDecl
where Arc<str>: Sync, RawVecInner: Sync,

§

impl Unpin for CounterDecl
where Arc<str>: Unpin, *const u8 is !null: Unpin,

§

impl UnsafeUnpin for CounterDecl

§

impl UnwindSafe for CounterDecl
where Arc<str>: UnwindSafe, RawVecInner: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.