pub struct Within {
pub parents: Parents,
pub joiner: WithinJoinerSpec,
pub no_restart: bool,
}Expand description
The counter within which a counter is numbered, and how that counter’s number is written before the counter’s own: the counter’s place in the hierarchy of counters.
A subsection numbered within a section is written 2.3: the parent is the
counter flm.headings.section, and the within-joiner is the joining text
.. The two are declared together because the parent decides what
restarts the counter and the within-joiner decides what is shown of the
parent, and neither is of any use without the other. The module
documentation describes the
mechanism.
Three constructors say which counter is the parent:
Within::parent: numbered within that one counter.Within::parents: numbered within whichever of several counters was advanced most recently in document order.Within::parent_set: the same over the counters of a parent set that a feature registered (ParentSetDecl).
Each writes the parent’s number and a full stop before the counter’s own
number, 1.2. Four builders change what is written:
joined_by: another joining text.template: a within template, which may write markup around an ancestor’s number and may refer to more than one ancestor.displayed_bare: nothing of the parent is written; the counter restarts under the parent and its number is shown bare.joiner_named: a within-joiner that a feature registered by name, which writes what its code writes.
The builder no_restart keeps the parent’s number
written before the counter’s own but stops the parent from restarting the
count: 1.1, 1.2, 2.3.
§Examples
use flm_core::stdlib::features::numbering::Within;
// `1.2`, the usual shape.
let plain = Within::parent("flm.headings.section");
// `1-2`.
let dashed = Within::parent("flm.headings.section").joined_by("-");
// The section's number in bold, then a full stop.
let bold = Within::parent("flm.headings.section").template(r"\textbf{#{flm.headings.section}}.");
// The same, referring to the parent that applies rather than to the counter.
let short = Within::parent("flm.headings.section").template(r"\textbf{#{_parent}}.");
// Restarted by the section, and shown without the section's number.
let bare = Within::parent("flm.headings.section").displayed_bare();
// What the within-joiner registered under this name writes.
let custom = Within::parent("flm.headings.section").joiner_named("example.compact");
// Within whichever of the three was advanced last: `4.1`, `4.1.2`.
let any = Within::parents([
"example.chapter",
"flm.headings.section",
"flm.headings.subsection",
]);
// The same over the heading counters a registry declares.
let levels = Within::parent_set("flm.headings.levels");
// `1.1`, `1.2`, then `2.3`: the section is written and does not restart.
let continued = Within::parent("flm.headings.section").no_restart();Fields§
§parents: ParentsThe counter within which this counter is numbered, or the counters any one of which may be its parent. The parent that applies restarts this counter: the counter’s count is kept separately for each list of ancestors it is advanced under, each ancestor identified by its name and its value.
joiner: WithinJoinerSpecThe within-joiner: how the ancestors’ numbers are written before this counter’s own.
no_restart: boolWhether the parent is left out of what restarts the count. true
continues the count across the parent’s advances, and the parent’s
number is still written before the counter’s own (1.1, 1.2,
2.3). false by default.
Implementations§
Source§impl Within
impl Within
Sourcepub fn parent(parent: impl Into<Name>) -> Within
pub fn parent(parent: impl Into<Name>) -> Within
Returns the place of a counter numbered within parent, whose number
is written before the counter’s own with a full stop after it: 1.2.
Sourcepub fn parents(parents: impl IntoIterator<Item = impl Into<Name>>) -> Within
pub fn parents(parents: impl IntoIterator<Item = impl Into<Name>>) -> Within
Returns the place of a counter numbered within whichever of parents
was advanced most recently in document order; that counter’s number is
written before the counter’s own with a full stop after it.
A reference point that the document reaches before any of parents
was advanced takes no number and is reported as the Error
flm.numbering.parent-uninitialized, as is a point under a single
parent that has no value yet.
Sourcepub fn parent_set(name: impl Into<Name>) -> Within
pub fn parent_set(name: impl Into<Name>) -> Within
Returns the place of a counter numbered within whichever counter of the
parent set name was advanced most recently, as Within::parents
does over the counters of the set. The parent set is one that a feature
registered as a ParentSetDecl.
Sourcepub fn no_restart(self) -> Within
pub fn no_restart(self) -> Within
Builder: the parent no longer restarts the count, which goes on across
the parent’s advances; the parent’s number is still written before the
counter’s own: 1.1, 1.2, then 2.3 after the second section.
Only the parent is left out of what the count is kept under; the parent’s own ancestors still restart the count.
Sourcepub fn joined_by(self, text: impl Into<String>) -> Within
pub fn joined_by(self, text: impl Into<String>) -> Within
Builder: the parent’s number is followed by text instead of a full
stop. The text is FLM.
Sourcepub fn template(self, text: impl Into<String>) -> Within
pub fn template(self, text: impl Into<String>) -> Within
Builder: the ancestors’ numbers are written by the within template
text.
A within template is FLM in which #{name} writes the counter name:
that counter’s value in that counter’s own counter style, the number
alone with no word and no delimiters, preceded by its own ancestors’
numbers. #{_parent} (PARENT_PLACEHOLDER) writes the parent that
applies in the same way: the only parent, or among several the one
advanced most recently. Every other character is written as given, and
markup may surround a substitution: \textbf{#{flm.headings.section}}.
writes the section’s number in bold. A counter’s name is the whole text
between the braces, dots included.
A substitution may carry keys between brackets, separated by commas:
#[Roman]{flm.headings.section} writes the section in that number
format instead of in its own counter style’s, and
#[bare]{flm.headings.section} writes the section’s own number without
its ancestors’ numbers. A key that is neither bare nor the name of a
number format is refused when the template is compiled.
The template writes one part per substitution, holding
the text after it (the text before the first substitution belongs to
the first part); a template that markup prevents from being cut at its
substitutions writes one part for all of them. A template that holds
text and no substitution writes one part that shows no ancestor, and
the empty template writes no part. To write nothing of the parent,
displayed_bare says so directly.
Sourcepub fn displayed_bare(self) -> Within
pub fn displayed_bare(self) -> Within
Builder: nothing of the ancestors is written. The counter still
restarts under its parent (it is counted separately for each value of
the parent), and its number is shown bare, that is, without its
parents’ numbers, as #[bare]{counter} writes an ancestor in a
within template.
Sourcepub fn joiner_named(self, name: impl Into<Name>) -> Within
pub fn joiner_named(self, name: impl Into<Name>) -> Within
Builder: the ancestors’ numbers are written by the within-joiner
registered under name in WITHIN_JOINERS_SLOT.
Source§impl Within
impl Within
Sourcepub fn compile(
&self,
lang: &BuiltLang,
counters: &[Name],
joiners: &[Arc<dyn WithinJoiner>],
) -> Result<Arc<dyn CompiledWithinJoiner>, StyleError>
pub fn compile( &self, lang: &BuiltLang, counters: &[Name], joiners: &[Arc<dyn WithinJoiner>], ) -> Result<Arc<dyn CompiledWithinJoiner>, StyleError>
Returns this declaration’s within-joiner compiled against the built language, ready to write parts.
counters are the counters a within template may refer to, and
joiners the within-joiners registered by name. The numbering feature
compiles every declaration itself when the registry is built; a caller
that writes numbers of its own, outside the feature, compiles one with
this method. Each call builds a template language of its own when the
form needs one, whereas the feature builds one for all the
declarations it compiles.
§Errors
The StyleError of a text that is not valid FLM, of a template that
does not compile, and StyleError::UnknownJoiner for a name that no
within-joiner in joiners has.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Within
impl<'de> Deserialize<'de> for Within
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 Within
Source§impl JsonSchema for Within
impl JsonSchema for Within
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 moreimpl StructuralPartialEq for Within
Auto Trait Implementations§
impl Forget for Within
impl Freeze for Withinwhere
*const ArcInner<str> is !null: Freeze,
PhantomData<ArcInner<str>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<Name>: Freeze,
PhantomData<u8>: Freeze,
impl Move for Within
impl RefUnwindSafe for Within
impl Send for Within
impl Sync for Within
impl Unpin for Within
impl UnsafeUnpin for Withinwhere
*const ArcInner<str> is !null: UnsafeUnpin,
PhantomData<ArcInner<str>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Name>: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
impl UnwindSafe for Within
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