pub struct Template { /* private fields */ }Expand description
A parsed path template.
Implementations§
Source§impl Template
impl Template
Sourcepub fn parse(source: &str) -> Result<Self, TemplateError>
pub fn parse(source: &str) -> Result<Self, TemplateError>
Parses a template, validating its placeholders.
Whitespace inside the braces is insignificant, so {{pad day}},
{{ pad day }} and {{ pad day }} are the same placeholder.
§Errors
Returns TemplateError if a placeholder is unclosed or unrecognised,
or if the template is missing the year or day placeholder - both are
always substituted, so a template without them can never render.
use aoc_runtime::template::{Segment, Template};
let template = Template::parse("/aoc/{{year}}/day{{ pad day }}")?;
assert_eq!(template.segments(), [
Segment::Literal("/aoc/".into()),
Segment::Year,
Segment::Literal("/day".into()),
Segment::Day { padded: true },
]);Sourcepub fn render(&self, params: Params) -> PathBuf
pub fn render(&self, params: Params) -> PathBuf
Renders the template into a concrete project path.
Infallible: Params carries validated values, and parsing has already
rejected templates that cannot be rendered.
Sourcepub fn matcher(&self) -> Result<CwdMatcher, TemplateError>
pub fn matcher(&self) -> Result<CwdMatcher, TemplateError>
Compiles the matcher that recovers parameters from a directory path.
§Errors
Returns TemplateError::Regex if the generated pattern is rejected,
which in practice only happens for pathologically large templates.
Sourcepub fn has_language(&self) -> bool
pub fn has_language(&self) -> bool
Whether the template mentions the language placeholder.
Trait Implementations§
impl Eq for Template
impl StructuralPartialEq for Template
Auto Trait Implementations§
impl Freeze for Template
impl RefUnwindSafe for Template
impl Send for Template
impl Sync for Template
impl Unpin for Template
impl UnsafeUnpin for Template
impl UnwindSafe for Template
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.