pub struct ListKind {
pub numbered: bool,
pub labels: Vec<String>,
pub ref_labels: Vec<String>,
pub nesting: WithinJoinerSpec,
}Expand description
A list kind: what every list environment of one name is, how its items are numbered and which labels are shown beside them.
A list kind states three facts:
numbered: whether its items are numbered. The items of a numbered list kind are numbered by thenumberingfeature, in a counter of the list kind’s own (flm.lists.<kind>; seeCounterDecl), and a reference to one of them shows its number. The items of an unnumbered list kind are counted in no counter.labels: how the label beside an item is written, one label template per nesting depth. The first template serves a list that is inside no list of the same list kind, the second a list nested in one such list, and so on; the last template serves every deeper list. A label template is written in the language of a counter style’s number template (NumberTemplate): every#{name}is the item’s number in the number formatname(#{arabic},#{alph},#{roman}, …), and every other character is FLM text written as is, so(#{roman})writes(ii)for the second item. A template that writes no number format, such as•, is a fixed label, shown beside every item.ref_labels: how a reference to an item writes the item’s number, one reference template per nesting depth, by the same rules and in the same language; read for a numbered list kind only. The two templates differ where the label carries punctuation that does not belong in a sentence:enumerateshows1.beside its first item, and\refto that item showsItem~1, because its first label template is#{arabic}.and its first reference template is#{arabic}. The constructorsnumberedandunnumberedgive a list kind the same templates for both;ref_labelssets the reference templates separately.
Whether a list kind is numbered is set by numbered alone and never
follows from its templates. A numbered list kind may show a fixed label
beside each item; every item still has a number, which a reference to it
or another feature can read. An unnumbered list kind whose label template
writes a number format is refused when the registry is built, since its
items have no number to write. An unnumbered list kind’s reference
templates are ignored (neither compiled nor checked), so that switching a
list kind between numbered and unnumbered needs no other change; a
reference to one of its items shows the item’s label.
A numbered list kind also has a nesting joiner:
what an item of a list nested in another list of the same list kind
writes of the enclosing item’s number before its own. By default it
writes nothing, so the second item of a list nested in the second item of
an enumerate shows (ii); the template #{_parent}. makes it
2.(ii). The enclosing item’s number is written through the enclosing
list’s reference template, as a reference to that item writes it: 2 for
the shipped enumerate, not 2.. The joiner is data of the numbering
feature, the same WithinJoinerSpec that a counter numbered within
another counter declares, and that feature compiles it; see
scoped instances
and the numbering guide.
§Examples
use flm_core::stdlib::features::lists::{ListKind, ListsConfig};
use flm_core::stdlib::features::numbering::WithinJoinerSpec;
// Items labeled `1.`, `2.`, referred to as `Step~1`, `Step~2`; a nested
// list's items labeled `1.a`, `1.b`: the enclosing number is written
// through its reference template, then the joiner's full stop.
let steps = ListKind::numbered(["#{arabic}.", "#{alph}"])
.ref_labels(["#{arabic}", "#{alph}"])
.nesting(WithinJoinerSpec::Template("#{_parent}.".to_string()));
assert!(steps.numbered);
assert_eq!(steps.label_at(5), Some("#{alph}"));
assert_eq!(steps.ref_label_at(1), Some("#{arabic}"));
assert_eq!(
text(
ListsConfig::new().environment("steps", steps),
r"\begin{steps}\item a\begin{steps}\item\label{item:y} x\item y\end{steps}\end{steps}
See \ref{item:y}.",
),
"1. a\n\n 1.a x\n\n 1.b y\n\nSee Item\u{a0}1.a.",
);
// A list of dashes at every depth.
let dashes = ListKind::unnumbered(["--"]);
assert_eq!(dashes.label_at(1), Some("--"));Fields§
§numbered: boolWhether the items of a list of this list kind are numbered.
labels: Vec<String>The label templates by nesting depth, the outermost first; the last
one serves every deeper list. An empty vector means that no label is
shown unless the author writes one: every item must then carry a tag,
as in a description list. A numbered list kind has at least one.
ref_labels: Vec<String>The reference templates by nesting depth, the outermost first; the
last one serves every deeper list. For a numbered list kind, each is
the number format of the counter style of its depth: it is what a
reference to an item shows (Item~1) and what the nesting joiner
writes of an enclosing item. A numbered list kind has at least one.
For an unnumbered list kind they are ignored: its items have no
number, and a reference to one of them shows its label.
nesting: WithinJoinerSpecFor a numbered list kind, what an item of a nested list of this list
kind writes of the enclosing item’s number; unused for an unnumbered
one. WithinJoinerSpec::Bare, which writes nothing, by default.
Implementations§
Source§impl ListKind
impl ListKind
Sourcepub fn numbered(labels: impl IntoIterator<Item = impl Into<String>>) -> ListKind
pub fn numbered(labels: impl IntoIterator<Item = impl Into<String>>) -> ListKind
A numbered list kind that writes labels, by depth, beside its items
and in a reference to one of them, with a nesting joiner that writes
nothing of the enclosing item. ref_labels
sets the reference templates separately.
Sourcepub fn unnumbered(
labels: impl IntoIterator<Item = impl Into<String>>,
) -> ListKind
pub fn unnumbered( labels: impl IntoIterator<Item = impl Into<String>>, ) -> ListKind
An unnumbered list kind that writes labels, by depth, beside its
items and in a reference to one of them. No label template may write a
number format: the registry build refuses one. The reference templates
are set to the same texts and are ignored.
Sourcepub fn ref_labels(
self,
ref_labels: impl IntoIterator<Item = impl Into<String>>,
) -> ListKind
pub fn ref_labels( self, ref_labels: impl IntoIterator<Item = impl Into<String>>, ) -> ListKind
Builder: sets the reference templates by depth, which the constructors set to the label templates. Read for a numbered list kind only.
Sourcepub fn nesting(self, nesting: WithinJoinerSpec) -> ListKind
pub fn nesting(self, nesting: WithinJoinerSpec) -> ListKind
Builder: sets the nesting joiner, read for a numbered list kind only.
Sourcepub fn label_at(&self, depth: usize) -> Option<&str>
pub fn label_at(&self, depth: usize) -> Option<&str>
The label template of a list at nesting depth depth, where depth 1
is a list inside no list of the same list kind (depth 0 is read as 1).
A depth past the last template gets the last template; a list kind
that declares no template gets None.
Sourcepub fn ref_label_at(&self, depth: usize) -> Option<&str>
pub fn ref_label_at(&self, depth: usize) -> Option<&str>
The reference template of a list at nesting depth depth, chosen as
label_at chooses a label template; None for a
list kind that declares none.
Sourcepub fn depth_count(&self) -> usize
pub fn depth_count(&self) -> usize
The number of nesting depths for which the list kind declares a
template, label or reference: the length of the longer of its two
vectors. A numbered list kind declares one counter style per such depth
(numbers).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ListKind
impl<'de> Deserialize<'de> for ListKind
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 ListKind
Source§impl JsonSchema for ListKind
impl JsonSchema for ListKind
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 ListKind
Auto Trait Implementations§
impl Forget for ListKind
impl Freeze for ListKind
impl Move for ListKind
impl RefUnwindSafe for ListKind
impl Send for ListKind
impl Sync for ListKind
impl Unpin for ListKind
impl UnsafeUnpin for ListKind
impl UnwindSafe for ListKind
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