pub trait Operatewhere
Self: Sized,{
// Provided methods
fn is_for_other_host(&self, hostname_sep: &str) -> bool { ... }
fn absolute(self) -> Result<Self> { ... }
fn host_specific(self, hostname_sep: &str) -> Self { ... }
fn non_host_specific(self, hostname_sep: &str) -> Self { ... }
fn nearest_existing_parent(&self) -> Self { ... }
fn is_parent_readonly(&self) -> bool { ... }
fn has_file_as_parent(&self) -> bool { ... }
fn is_twisted(&self) -> bool { ... }
fn make_target<P>(
self,
hostname_sep: &str,
base: &Self,
targetbase: P,
renaming_rules: Vec<RenamingRule>,
) -> Result<Self>
where P: AsRef<Path> { ... }
fn get_content<R: Register, O: Operate>(
&self,
registry: &Rc<R>,
group: &Rc<Group<O>>,
) -> Result<Vec<u8>> { ... }
fn populate<T: Register>(
&self,
group: Rc<Group<Self>>,
registry: Rc<T>,
) -> Result<()> { ... }
fn populate_dry(&self, group: Rc<LocalGroup>) -> Result<()> { ... }
}Expand description
Defines shared behaviours for an item (a path to a file) used in DT.
Provided Methods§
Sourcefn is_for_other_host(&self, hostname_sep: &str) -> bool
fn is_for_other_host(&self, hostname_sep: &str) -> bool
Checks if the item is for another machine.
Sourcefn host_specific(self, hostname_sep: &str) -> Self
fn host_specific(self, hostname_sep: &str) -> Self
Gets the host-specific counterpart of self, if applicable. If
self is already host-specific, returns self directly.
Sourcefn non_host_specific(self, hostname_sep: &str) -> Self
fn non_host_specific(self, hostname_sep: &str) -> Self
Gets the non-host-specific counterpart of self, if applicable. If
self is already non-host-specific, returns self directly.
Sourcefn nearest_existing_parent(&self) -> Self
fn nearest_existing_parent(&self) -> Self
Gets the nearest existing parent component of self.
Sourcefn is_parent_readonly(&self) -> bool
fn is_parent_readonly(&self) -> bool
Checks whether any of the component above self is readonly.
Sourcefn has_file_as_parent(&self) -> bool
fn has_file_as_parent(&self) -> bool
Checks whether any component of self’s parent is not a directory.
Sourcefn is_twisted(&self) -> bool
fn is_twisted(&self) -> bool
Checks whether any of the component references its parent.
Sourcefn make_target<P>(
self,
hostname_sep: &str,
base: &Self,
targetbase: P,
renaming_rules: Vec<RenamingRule>,
) -> Result<Self>
fn make_target<P>( self, hostname_sep: &str, base: &Self, targetbase: P, renaming_rules: Vec<RenamingRule>, ) -> Result<Self>
Given a hostname_sep, a base, a targetbase, and optionally a
list of [renaming rule]s, creates the path where self would be
synced to. Renaming rules are applied after host-specific suffixes
are stripped.
Sourcefn get_content<R: Register, O: Operate>(
&self,
registry: &Rc<R>,
group: &Rc<Group<O>>,
) -> Result<Vec<u8>>
fn get_content<R: Register, O: Operate>( &self, registry: &Rc<R>, group: &Rc<Group<O>>, ) -> Result<Vec<u8>>
Renders this item with given context to the dest path.
Sourcefn populate<T: Register>(
&self,
group: Rc<Group<Self>>,
registry: Rc<T>,
) -> Result<()>
fn populate<T: Register>( &self, group: Rc<Group<Self>>, registry: Rc<T>, ) -> Result<()>
Populate this item with given group config. The given group config is expected to be the group where this item belongs to.
Sourcefn populate_dry(&self, group: Rc<LocalGroup>) -> Result<()>
fn populate_dry(&self, group: Rc<LocalGroup>) -> Result<()>
Show what is to be done if this item is to be populated with given group config. The given group config is expected to be the group where this item belongs to.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Operate for PathBuf
impl Operate for PathBuf
Source§fn is_for_other_host(&self, hostname_sep: &str) -> bool
fn is_for_other_host(&self, hostname_sep: &str) -> bool
Checks if the item is for another machine (by checking its name).
A host-specific item is considered for another machine, when its
filename contains only 1 hostname_sep, and after the
hostname_sep should not be current machine’s hostname.
A non-host-specific item is always considered not for another machine (because it is non-host-specific, i.e. for all machines).
An item with filename containing more than 1 hostname_sep causes
this function to panic.
Source§fn absolute(self) -> Result<Self>
fn absolute(self) -> Result<Self>
Gets the absolute path of self, without traversing symlinks.
Source§fn host_specific(self, hostname_sep: &str) -> Self
fn host_specific(self, hostname_sep: &str) -> Self
Gets the host-specific counterpart of self. If self is already
host-specific, returns self directly.
Source§fn non_host_specific(self, hostname_sep: &str) -> Self
fn non_host_specific(self, hostname_sep: &str) -> Self
Converts a path to a non-host-specific path. If the input path is already non-host-specific, returns itself; Otherwise returns a path where every component of the path is converted to a non-host-specific one.
§Example
let itm: PathBuf = "/some/long/path".into();
assert_eq!(
itm.non_host_specific("@@"),
PathBuf::from_str("/some/long/path").unwrap(),
);
let itm: PathBuf = "/some@@john/long/path@@watson".into();
assert_eq!(
itm.non_host_specific("@@"),
PathBuf::from_str("/some/long/path").unwrap(),
);Source§fn nearest_existing_parent(&self) -> Self
fn nearest_existing_parent(&self) -> Self
Gets the nearest existing parent component of self.
Source§fn is_parent_readonly(&self) -> bool
fn is_parent_readonly(&self) -> bool
Checks whether any of the component above self is readonly.
Source§fn has_file_as_parent(&self) -> bool
fn has_file_as_parent(&self) -> bool
Checks whether any component of self’s parent is not a directory.
Source§fn is_twisted(&self) -> bool
fn is_twisted(&self) -> bool
Checks whether any of the component references its parent.
Source§fn make_target<P: AsRef<Path>>(
self,
hostname_sep: &str,
base: &Self,
targetbase: P,
renaming_rules: Vec<RenamingRule>,
) -> Result<Self>
fn make_target<P: AsRef<Path>>( self, hostname_sep: &str, base: &Self, targetbase: P, renaming_rules: Vec<RenamingRule>, ) -> Result<Self>
Given a hostname_sep, a base, a targetbase, and optionally a
list of renaming rules, create the path where self would be synced
to. Renaming rules are applied after host-specific suffixes are
stripped.
§Example
§No renaming rule
let itm: PathBuf = "/path/to/source@@john/item".into();
let base: PathBuf = "/path/to/source".into();
let targetbase: PathBuf = "/path/to/target".into();
assert_eq!(
itm.make_target("@@", &base, &targetbase, vec![])?,
PathBuf::from_str("/path/to/target/item").unwrap(),
);§Single renaming rule
let itm: PathBuf = "/path/to/source@@john/_dot_item".into();
let base: PathBuf = "/path/to/source".into();
let targetbase: PathBuf = "/path/to/target".into();
let rules = vec![
RenamingRule{
pattern: regex::Regex::new("^_dot_").unwrap(),
substitution: ".".into(),
},
];
assert_eq!(
itm.make_target("@@", &base, &targetbase, rules)?,
PathBuf::from_str("/path/to/target/.item").unwrap(),
);§Multiple renaming rules
When multiple renaming rules are supplied, they are applied one after another.
let itm: PathBuf = "/path/to/source@@john/_dot_item.ext".into();
let base: PathBuf = "/path/to/source".into();
let targetbase: PathBuf = "/path/to/target".into();
let rules = vec![
RenamingRule{
pattern: regex::Regex::new("^_dot_").unwrap(),
substitution: ".".into(),
},
RenamingRule{
pattern: regex::Regex::new("^.").unwrap(),
substitution: "_dotted_".into(),
},
];
assert_eq!(
itm.make_target("@@", &base, &targetbase, rules)?,
PathBuf::from_str("/path/to/target/_dotted_item.ext").unwrap(),
);§Capture groups
let itm: PathBuf = "/path/to/source@@john/_dot_item.ext".into();
let base: PathBuf = "/path/to/source".into();
let targetbase: PathBuf = "/path/to/target".into();
let named_capture = RenamingRule{
// Named capture group, captures "dot" into a group with name
// "prefix".
pattern: regex::Regex::new("^_(?P<prefix>.*)_").unwrap(),
substitution: ".${prefix}.".into(),
};
assert_eq!(
itm.to_owned().make_target(
"@@",
&base,
&targetbase,
vec![named_capture]
)?,
PathBuf::from_str("/path/to/target/.dot.item.ext").unwrap(),
);
let numbered_capture = RenamingRule{
// Numbered capture group, where `${0}` references the whole match,
// other groups are indexed from 1.
pattern: regex::Regex::new(r#"\.(.*?)$"#).unwrap(),
substitution: "_${1}_${0}".into(),
};
assert_eq!(
itm.to_owned().make_target(
"@@",
&base,
&targetbase,
vec![numbered_capture]
)?,
PathBuf::from_str("/path/to/target/_dot_item_ext_.ext").unwrap(),
);Source§fn populate<T: Register>(
&self,
group: Rc<LocalGroup>,
registry: Rc<T>,
) -> Result<()>
fn populate<T: Register>( &self, group: Rc<LocalGroup>, registry: Rc<T>, ) -> Result<()>
Populate this item with given group config. The given group config is expected to be the group where this item belongs to.
Source§fn populate_dry(&self, group: Rc<LocalGroup>) -> Result<()>
fn populate_dry(&self, group: Rc<LocalGroup>) -> Result<()>
Show what is to be done if this item is to be populated with given group config. The given group config is expected to be the group where this item belongs to.