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: &Template,
width: usize,
lifecycle: &[LifecycleDimension],
) -> Result<IdTemplate, Problem>
pub fn from_template( template: &Template, width: usize, lifecycle: &[LifecycleDimension], ) -> Result<IdTemplate, 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<IdTemplate, Problem>
pub fn fixed(id: &str) -> Result<IdTemplate, 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.
Trait Implementations§
Source§impl Clone for IdTemplate
impl Clone for IdTemplate
Source§fn clone(&self) -> IdTemplate
fn clone(&self) -> IdTemplate
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for IdTemplate
impl Debug for IdTemplate
impl Eq for IdTemplate
Source§impl PartialEq for IdTemplate
impl PartialEq for IdTemplate
impl StructuralPartialEq for IdTemplate
Auto Trait Implementations§
impl Forget for IdTemplate
impl Freeze for IdTemplate
impl Move for IdTemplate
impl RefUnwindSafe for IdTemplate
impl Send for IdTemplate
impl Sync for IdTemplate
impl Unpin for IdTemplate
impl UnsafeUnpin for IdTemplate
impl UnwindSafe for IdTemplate
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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.