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: NameThe counter style’s name: dotted, owned by the feature that declares it.
number_format: NumberTemplateThe 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: PrefixWordsThe prefix words: the word written before the number.
delimiters: DelimitersThe delimiters: the texts around the number.
join: JoinDeclThe join texts: the texts that join several numbers.
name_in_link: boolWhether 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: boolWhether 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: boolWhether 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
impl CounterStyleDecl
Sourcepub fn new(name: impl Into<Name>) -> CounterStyleDecl
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.
Sourcepub fn with_number_writer(self, name: impl Into<Name>) -> CounterStyleDecl
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.
Sourcepub fn compile(&self, lang: &BuiltLang) -> Result<CounterStyle, StyleError>
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.
Sourcepub fn compile_with(
&self,
lang: &BuiltLang,
language: &TemplateLanguage,
writers: &[Arc<dyn NumberWriter>],
) -> Result<CounterStyle, StyleError>
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
impl Clone for CounterStyleDecl
Source§impl Debug for CounterStyleDecl
impl Debug for CounterStyleDecl
Source§impl<'de> Deserialize<'de> for CounterStyleDecl
impl<'de> Deserialize<'de> for CounterStyleDecl
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for CounterStyleDecl
Source§impl JsonSchema for CounterStyleDecl
impl JsonSchema for CounterStyleDecl
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§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.
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>
fn read_entry(name: &str, data: Value) -> Result<CounterStyleDecl, String>
Source§impl PartialEq for CounterStyleDecl
impl PartialEq for CounterStyleDecl
Source§impl Serialize for CounterStyleDecl
impl Serialize for CounterStyleDecl
impl StructuralPartialEq for CounterStyleDecl
Auto Trait Implementations§
impl Forget for CounterStyleDecl
impl Freeze for CounterStyleDecl
impl Move for CounterStyleDecl
impl RefUnwindSafe for CounterStyleDecl
impl Send for CounterStyleDecl
impl Sync for CounterStyleDecl
impl Unpin for CounterStyleDecl
impl UnsafeUnpin for CounterStyleDecl
impl UnwindSafe for CounterStyleDecl
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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