pub struct SpecifierContext { /* private fields */ }Expand description
Context for expanding systemd specifiers
This contains the values that will be substituted when expanding specifiers in unit file values.
Implementations§
Source§impl SpecifierContext
impl SpecifierContext
Sourcepub fn set(&mut self, specifier: &str, value: &str)
pub fn set(&mut self, specifier: &str, value: &str)
Set a specifier value
§Example
let mut ctx = SpecifierContext::new();
ctx.set("i", "instance");
ctx.set("u", "user");Sourcepub fn with_unit_name(unit_name: &str) -> Self
pub fn with_unit_name(unit_name: &str) -> Self
Create a context with common system specifiers
This sets up commonly used specifiers with their values:
%n: Unit name (without type suffix)%N: Full unit name%p: Prefix (for template units)%i: Instance (for template units)
§Example
let ctx = SpecifierContext::with_unit_name("foo@bar.service");
assert_eq!(ctx.get("N"), Some("foo@bar.service"));
assert_eq!(ctx.get("n"), Some("foo@bar"));
assert_eq!(ctx.get("p"), Some("foo"));
assert_eq!(ctx.get("i"), Some("bar"));Sourcepub fn expand(&self, input: &str) -> String
pub fn expand(&self, input: &str) -> String
Expand specifiers in a string
This replaces all %X patterns with their corresponding values from the context.
%% is replaced with a single %.
§Example
let mut ctx = SpecifierContext::new();
ctx.set("i", "myinstance");
ctx.set("u", "myuser");
let result = ctx.expand("/var/lib/%i/data/%u");
assert_eq!(result, "/var/lib/myinstance/data/myuser");Trait Implementations§
Source§impl Clone for SpecifierContext
impl Clone for SpecifierContext
Source§fn clone(&self) -> SpecifierContext
fn clone(&self) -> SpecifierContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SpecifierContext
impl Debug for SpecifierContext
Source§impl Default for SpecifierContext
impl Default for SpecifierContext
Source§fn default() -> SpecifierContext
fn default() -> SpecifierContext
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SpecifierContext
impl RefUnwindSafe for SpecifierContext
impl Send for SpecifierContext
impl Sync for SpecifierContext
impl Unpin for SpecifierContext
impl UnsafeUnpin for SpecifierContext
impl UnwindSafe for SpecifierContext
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
Mutably borrows from an owned value. Read more