use std::fmt::{
self,
Display,
Formatter,
};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ArgumentPath(String);
impl ArgumentPath {
#[inline]
pub fn new(path: &str) -> Self {
Self(path.to_owned())
}
#[inline]
pub fn as_str(&self) -> &str {
self.0.as_str()
}
#[inline]
pub fn with_prefix(self, prefix: &str) -> Self {
if prefix.is_empty() {
return self;
}
if self.0.is_empty() {
return Self(prefix.to_owned());
}
let mut path = String::with_capacity(prefix.len() + 1 + self.0.len());
path.push_str(prefix);
path.push('.');
path.push_str(&self.0);
Self(path)
}
}
impl AsRef<str> for ArgumentPath {
#[inline]
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl Display for ArgumentPath {
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_str())
}
}