pub struct TemplatedPathBuf { /* private fields */ }Expand description
A path buffer that can contain template variables like {PID} and {TIMESTAMP}.
This type stores both the original template and its evaluated form. Templates are evaluated on creation and can be re-evaluated to get fresh dynamic values.
Supported placeholders (case-insensitive, any case combination allowed):
{PID},{pid},{Pid}, etc.: Process ID of the current process{TIMESTAMP},{timestamp},{TimeStamp}, etc.: ISO 8601 timestamp in local timezone with offset (e.g.,2024-02-05T14-30-45-0500for EST,2024-02-05T19-30-45+0000for UTC)
§Usage
- Use
new()to create aTemplatedPathBufthat stores both template and evaluated path - Use
as_path()to get a reference to the evaluated path - Use
re_evaluate()to refresh dynamic values like{TIMESTAMP} - Use
evaluate()static method for one-time evaluation without keeping the template
§Path normalization
Path evaluation performs the following transformations:
- Expands
~to the user’s home directory - Replaces placeholders with actual values (timestamp uses local timezone with offset)
- Converts to an absolute path
Implementations§
Source§impl TemplatedPathBuf
impl TemplatedPathBuf
Sourcepub fn new(path: impl Into<PathBuf>) -> Self
pub fn new(path: impl Into<PathBuf>) -> Self
Creates a new TemplatedPathBuf from a path-like value.
Sourcepub fn evaluate(path: impl Into<PathBuf>) -> PathBuf
pub fn evaluate(path: impl Into<PathBuf>) -> PathBuf
Convenience function to create and evaluate a template in one step.
This is equivalent to calling TemplatedPathBuf::new(path).as_path().to_path_buf().
Use this when you don’t need to keep the template around.
Sourcepub fn as_path(&self) -> &Path
pub fn as_path(&self) -> &Path
Returns a reference to the evaluated path.
The evaluated path has all template variables substituted with their actual values, tilde expansion applied, and is converted to an absolute path.
Sourcepub fn template_string(&self) -> String
pub fn template_string(&self) -> String
Returns the original template path as a string.
Sourcepub fn re_evaluate(&mut self) -> &Path
pub fn re_evaluate(&mut self) -> &Path
Re-evaluates the template by replacing all placeholders with fresh values and expanding paths.
This method updates the internal evaluated path and returns a reference to it.
Call this if you need to refresh dynamic values like {PID} or {TIMESTAMP}.
§Examples
use xet_runtime::utils::TemplatedPathBuf;
let mut template = TemplatedPathBuf::new("~/logs/app_{PID}_{TIMESTAMP}.txt");
let path = template.as_path();
// Returns an absolute path like "/home/user/logs/app_12345_2024-01-15T10-30-45-0500.txt"
// (timestamp in local timezone with offset appended)
// Later, re-evaluate to get a fresh timestamp
template.re_evaluate();
let new_path = template.as_path();Trait Implementations§
Source§impl Clone for TemplatedPathBuf
impl Clone for TemplatedPathBuf
Source§fn clone(&self) -> TemplatedPathBuf
fn clone(&self) -> TemplatedPathBuf
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TemplatedPathBuf
impl Debug for TemplatedPathBuf
Source§impl From<&Path> for TemplatedPathBuf
impl From<&Path> for TemplatedPathBuf
Source§impl From<&str> for TemplatedPathBuf
impl From<&str> for TemplatedPathBuf
Source§impl From<PathBuf> for TemplatedPathBuf
impl From<PathBuf> for TemplatedPathBuf
Source§impl From<String> for TemplatedPathBuf
impl From<String> for TemplatedPathBuf
Source§impl ParsableConfigValue for TemplatedPathBuf
Available on non-target_family=wasm only.
impl ParsableConfigValue for TemplatedPathBuf
target_family=wasm only.fn parse_user_value(value: &str) -> Option<Self>
Source§fn to_config_string(&self) -> String
fn to_config_string(&self) -> String
parse_user_value.Source§fn try_update_in_place(&mut self, value: &str) -> bool
fn try_update_in_place(&mut self, value: &str) -> bool
parse_user_value, but types like
ConfigEnum override this to use context-aware validation.