Skip to main content

Within

Struct Within 

Source
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:

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: Parents

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

The within-joiner: how the ancestors’ numbers are written before this counter’s own.

§no_restart: bool

Whether 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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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

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 Within

Source§

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

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

impl<'de> Deserialize<'de> for Within

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 Within

Source§

impl Hash for Within

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl JsonSchema for Within

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 Within

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 Within

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 Within

Auto Trait Implementations§

§

impl Forget for Within

§

impl Freeze for Within
where *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
where Arc<str>: Send, RawVecInner: Send,

§

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

§

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

§

impl UnsafeUnpin for Within

§

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