Skip to main content

ListKind

Struct ListKind 

Source
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 the numbering feature, in a counter of the list kind’s own (flm.lists.<kind>; see CounterDecl), 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 format name (#{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: enumerate shows 1. beside its first item, and \ref to that item shows Item~1, because its first label template is #{arabic}. and its first reference template is #{arabic}. The constructors numbered and unnumbered give a list kind the same templates for both; ref_labels sets 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: bool

Whether 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: WithinJoinerSpec

For 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

Source

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.

Source

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.

Source

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.

Source

pub fn nesting(self, nesting: WithinJoinerSpec) -> ListKind

Builder: sets the nesting joiner, read for a numbered list kind only.

Source

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.

Source

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.

Source

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 Clone for ListKind

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 ListKind

Source§

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

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

impl<'de> Deserialize<'de> for ListKind

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 ListKind

Source§

impl JsonSchema for ListKind

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 PartialEq for ListKind

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 ListKind

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 ListKind

Auto Trait Implementations§

§

impl Forget for ListKind

§

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

§

impl Move for ListKind

§

impl RefUnwindSafe for ListKind

§

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

§

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

§

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

§

impl UnsafeUnpin for ListKind

§

impl UnwindSafe for ListKind
where RawVecInner: UnwindSafe, Arc<str>: 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> 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.