Skip to main content

CounterStyleDecl

Struct CounterStyleDecl 

Source
pub struct CounterStyleDecl {
    pub name: Name,
    pub number_format: NumberTemplate,
    pub sub_levels: Vec<SubLevelDecl>,
    pub prefix_words: PrefixWords,
    pub delimiters: Delimiters,
    pub join: JoinDecl,
    pub name_in_link: bool,
    pub repeat_parents_in_range: bool,
    pub ranges: bool,
    pub number_writer: Option<Name>,
}
Expand description

A counter style, as a feature declares it.

A counter style says how a counter value is shown: the number template, the sub-levels, the prefix words with their variants, the delimiters and the join texts, each text written in FLM and parsed once, when the counter style is compiled against the built language (compile) into a CounterStyle. It also holds three choices about links and ranges, and may ask for a number writer other than the default one. The concepts overview presents counters and counter styles together (counters and counter styles).

A feature contributes the declaration to the service slot STYLES_SLOT; a counter refers to its default counter style by name (CounterDecl::default_style), and a reference point gives the counter style of its number in its number source. A host replaces a declared counter style by name through NumberingConfig.

A counter style’s name is a dotted name owned by the feature that declares it, such as flm.math.style.equation, so that two features may each declare a counter style for the same counter without a clash.

§Examples

use flm_core::stdlib::features::numbering::{
    CounterStyleDecl, Delimiters, JoinDecl, NumberTemplate, PrefixWords,
};

let mut style = CounterStyleDecl::new("flm.math.style.equation");
style.number_format = NumberTemplate::formats("#{arabic}");
style.delimiters = Delimiters::new("(", ")");
style.prefix_words = PrefixWords::new("Eq.~", "Eqs.~")
    .with_variant("capital", flm_core::stdlib::features::numbering::PluralWords::new(
        "Equation~", "Equations~",
    ));
style.join = JoinDecl::compact();

In data, no field is required: each field the data gives replaces that field of a base counter style, and every other field keeps the base’s value. The base of an entry of NumberingConfig::styles is the counter style that CounterStyleDecl::new returns for the entry’s key, which is its name, not the declared counter style it replaces; the counter style in the citations feature’s configuration takes that feature’s default counter style as its base. The name is never written as a field.

Fields§

§name: Name

The counter style’s name: dotted, owned by the feature that declares it.

§number_format: NumberTemplate

The number template: how the number itself is written.

§sub_levels: Vec<SubLevelDecl>

The sub-levels, outermost first. A value cannot be written with a sub-number at a level the counter style does not declare.

§prefix_words: PrefixWords

The prefix words: the word written before the number.

§delimiters: Delimiters

The delimiters: the texts around the number.

§join: JoinDecl

The join texts: the texts that join several numbers.

§name_in_link: bool

Whether the word before the numbers is part of the link to the first number written. With one number written by format(), the whole text is one link regardless of this setting. On by default.

§repeat_parents_in_range: bool

Whether the end of a range repeats the part of the number that comes from the counters it is numbered within: A.I–A.III instead of A.I–III. Off by default.

§ranges: bool

Whether consecutive numbers collapse into a range: 1–3 when on, 1,2,3 when off. Several numbers are sorted in both cases, and when off every number is written separately, each with a link of its own. On by default.

§number_writer: Option<Name>

The name of the number writer that writes this counter style’s numbers, registered under that name in NUMBER_WRITERS_SLOT, or None for the default writer. A name no feature registers fails the registry build.

Implementations§

Source§

impl CounterStyleDecl

Source

pub fn new(name: impl Into<Name>) -> CounterStyleDecl

Returns a counter style named name that writes the number in decimal digits (#{arabic}), with no sub-level, no word, no delimiters, the default join texts, the word inside the link, no repeated ancestors’ part in a range, consecutive numbers collapsed into ranges, and the default number writer.

Source

pub fn with_number_writer(self, name: impl Into<Name>) -> CounterStyleDecl

Builder: this counter style’s numbers are written by the number writer registered under name.

A counter style that asks for no writer is written by the default writer, which writes what the counter style’s own data describes. A name no feature registers fails the registry build.

Source

pub fn compile(&self, lang: &BuiltLang) -> Result<CounterStyle, StyleError>

Returns this declaration compiled against the built language: every text parsed once, every number template compiled, every join variable replaced.

A caller that writes numbers of its own, outside the numbering feature, compiles a counter style with this method; the numbering feature compiles every declared counter style itself when the registry is built. This method knows no registered number writer, so it refuses a declaration that asks for one (compile_with accepts them).

§Errors

The StyleError of the first text that is not valid FLM or that refers to something that does not exist, and StyleError::UnknownWriter for a declaration that asks for a number writer.

Source

pub fn compile_with( &self, lang: &BuiltLang, language: &TemplateLanguage, writers: &[Arc<dyn NumberWriter>], ) -> Result<CounterStyle, StyleError>

Returns this declaration compiled as compile does, with an already built template language and with the number writers that features registered.

A caller that compiles many counter styles builds the template language once and passes it to each call. A declaration that asks for a writer that none of writers has is refused with StyleError::UnknownWriter.

§Errors

The same as compile, and StyleError::UnknownWriter.

Trait Implementations§

Source§

impl Clone for CounterStyleDecl

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 CounterStyleDecl

Source§

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

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

impl<'de> Deserialize<'de> for CounterStyleDecl

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for CounterStyleDecl

Source§

impl JsonSchema for CounterStyleDecl

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl NamedEntry for CounterStyleDecl

Reads a counter style from an entry of the settings key styles (NumberingConfig::styles). In settings data, styles is a map from the name of a counter style to its fields. The entry is read over the result of CounterStyleDecl::new for its name, so the fields missing from the entry keep the defaults of CounterStyleDecl::new.

Source§

fn read_entry(name: &str, data: Value) -> Result<CounterStyleDecl, String>

Reads the entry named name from data, the rest of the entry as written under that name. Read more
Source§

impl PartialEq for CounterStyleDecl

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 Serialize for CounterStyleDecl

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for CounterStyleDecl

Auto Trait Implementations§

§

impl Forget for CounterStyleDecl

§

impl Freeze for CounterStyleDecl
where *const ArcInner<str> is !null: Freeze, PhantomData<ArcInner<str>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<SubLevelDecl>: Freeze, *const LeafNode<String, PluralWords> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, PluralWords)>>: Freeze,

§

impl Move for CounterStyleDecl

§

impl RefUnwindSafe for CounterStyleDecl

§

impl Send for CounterStyleDecl
where Arc<str>: Send, RawVecInner: Send, NodeRef<Owned, String, PluralWords, LeafOrInternal>: Send, BoxRaw<(String, PluralWords)>: Send,

§

impl Sync for CounterStyleDecl
where Arc<str>: Sync, RawVecInner: Sync, NodeRef<Owned, String, PluralWords, LeafOrInternal>: Sync, BoxRaw<(String, PluralWords)>: Sync,

§

impl Unpin for CounterStyleDecl
where Arc<str>: Unpin, *const u8 is !null: Unpin, *const LeafNode<String, PluralWords> is !null: Unpin, Box<(String, PluralWords)>: Unpin,

§

impl UnsafeUnpin for CounterStyleDecl

§

impl UnwindSafe for CounterStyleDecl

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> SettingsData for T

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.