Skip to main content

Template

Struct Template 

Source
pub struct Template { /* private fields */ }
Expand description

A parsed path template: literal runs, $field / ${field} substitutions (with optional ${a|b} fallback chains and $!{field} slash-preserving path fields), and [...] conditional sections. Parse once per mount; render then costs one output String per call, with no re-parse.

Implementations§

Source§

impl Template

Source

pub fn parse(template: &str) -> Result<Template, TemplateError>

Parse a beets-style template. Returns Err for a template that cannot produce valid path components: control/NUL bytes in literal text (#275), [...] nesting deeper than [MAX_SECTION_DEPTH] (#304), an unterminated ${/$!{ field (no closing }), or an unclosed [ section (no closing ]).

  • $field / ${field} substitute a tag field; ${a|b|c} is a fallback chain (first present wins). Names are matched case-insensitively.
  • $!{field} is a path field: the value’s ‘/’ are kept as directory separators (each segment sanitized; empty / . / .. dropped).
  • [...] is a conditional section, suppressed when every field it references is empty. $[ and $] emit literal brackets.
  • A $ not followed by a recognized form stays literal. An unterminated ${/$!{ (missing }) or an unclosed [ section (missing ]) is a parse error.
Source

pub fn referenced_fields(&self) -> BTreeSet<String>

The set of field names this template references, across plain fields, $!{} path fields, | fallback chains, and [...] sections. Names are already ASCII-lowercased at parse time, matching tags_to_fields’s key folding, so a key-filtered tag load (Db::tags_grouped_for_keys) fetches exactly what rendering consumes.

Source

pub fn render( &self, fields: &BTreeMap<String, &str>, fallbacks: &BTreeMap<String, String>, default_fallback: &str, ext: &str, ) -> String

Render one track’s path. Outside a section a missing field resolves through fallbacks then default_fallback; inside a section a missing field renders blank and drives suppression. The extension follows a ‘.’.

Source

pub fn render_checked( &self, fields: &BTreeMap<String, &str>, fallbacks: &BTreeMap<String, String>, ext: &str, ) -> Option<String>

Like render, but returns None when any top-level (non-section) field is unresolved — the caller’s signal to skip the track rather than substitute default_fallback. Per-field fallback chains and [...] sections behave exactly as in render; only the top-level default substitution is replaced by the skip. Backs --skip-on-missing.

Trait Implementations§

Source§

impl Clone for Template

Source§

fn clone(&self) -> Template

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 Template

Source§

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

Formats the value using the given formatter. Read more

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

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.