Skip to main content

IdTemplate

Struct IdTemplate 

Source
pub struct IdTemplate {
    pub source: String,
    pub tokens: Vec<Token>,
}
Expand description

An id template a new document can be filled with.

Fields§

§source: String

The template as written.

§tokens: Vec<Token>

The tokens, in order.

Implementations§

Source§

impl IdTemplate

Source

pub fn from_template( template: &LineTemplate, width: usize, lifecycle: &[LifecycleDimension], ) -> Result<Self, Problem>

The id template of template, its sequence width digits wide, a hole named with no type standing for the state of the lifecycle key of its name. Refuses a hole a new document cannot be filled with, more than one seq, a zero width, a lifecycle key with a state that is not a slug, and a template that admits a non-slug.

Source

pub fn fixed(id: &str) -> Result<Self, Problem>

The id template of a fixed id, the const of id: one literal, a slug.

Source

pub fn seq_width(&self) -> Option<usize>

Whether the template carries a seq hole, and its width.

Source

pub fn has_slug(&self) -> bool

Whether the template carries a slug hole.

Source

pub fn has_keys(&self) -> bool

Whether the template carries a hole for a lifecycle key.

Source

pub fn regex(&self) -> String

An anchored regex matching the ids the template admits; the seq hole is the group seq, and a lifecycle key’s hole the group key_<name>.

Source

pub fn matches(&self, id: &str) -> bool

Whether id matches the template.

Source

pub fn seq_of(&self, id: &str) -> Option<u64>

The sequence number of id, when it matches and the template has a sequence.

Source

pub fn keys_of(&self, id: &str) -> Vec<(String, String)>

The lifecycle keys whose state id holds, each with that state, when id matches the template.

Source

pub fn render(&self, seq: u64, slug: Option<&str>) -> Result<String, String>

Render the id for seq and slug, each lifecycle key’s hole taking its first state. Refuses what IdTemplate::render_with refuses.

Source

pub fn render_with( &self, seq: u64, slug: Option<&str>, states: &States, ) -> Result<String, String>

Render the id for seq, slug and states, a lifecycle key’s hole taking the state states gives it, else its first. Refuses a sequence that needs more digits than the width, a missing slug, a slug that is not slug words, and a state that is not one of the key’s.

Trait Implementations§

Source§

impl Clone for IdTemplate

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 IdTemplate

Source§

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

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

impl Eq for IdTemplate

Source§

impl PartialEq for IdTemplate

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 StructuralPartialEq for IdTemplate

Auto Trait Implementations§

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

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> 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.