pub struct IdTemplate {
pub source: String,
pub tokens: Vec<Token>,
}Expand description
An id template a new document can be filled with.
Fields§
§source: StringThe template as written.
tokens: Vec<Token>The tokens, in order.
Implementations§
Source§impl IdTemplate
impl IdTemplate
Sourcepub fn from_template(
template: &LineTemplate,
width: usize,
lifecycle: &[LifecycleDimension],
) -> Result<Self, Problem>
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.
Sourcepub fn fixed(id: &str) -> Result<Self, Problem>
pub fn fixed(id: &str) -> Result<Self, Problem>
The id template of a fixed id, the const of id: one literal, a
slug.
Sourcepub fn seq_width(&self) -> Option<usize>
pub fn seq_width(&self) -> Option<usize>
Whether the template carries a seq hole, and its width.
Sourcepub fn regex(&self) -> String
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>.
Sourcepub fn seq_of(&self, id: &str) -> Option<u64>
pub fn seq_of(&self, id: &str) -> Option<u64>
The sequence number of id, when it matches and the template has a
sequence.
Sourcepub fn keys_of(&self, id: &str) -> Vec<(String, String)>
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.
Sourcepub fn render(&self, seq: u64, slug: Option<&str>) -> Result<String, String>
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.
Sourcepub fn render_with(
&self,
seq: u64,
slug: Option<&str>,
states: &States,
) -> Result<String, String>
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.