pub trait Operate where
    Self: Sized
{ 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 is_parent_readonly(&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

Checks if the item is for another machine.

Gets the absolute location of self, if applicable.

Gets the host-specific counterpart of self, if applicable. If self is already host-specific, returns self directly.

Gets the non-host-specific counterpart of self, if applicable. If self is already non-host-specific, returns self directly.

Checks whether any of the component above self is readonly.

Checks whether any of the component refernces its parent.

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.

Renders this item with given context to the dest path.

Populate this item with given group config. The given group config is expected to be the group where this item belongs to.

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.

Implementations on Foreign Types

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.

Gets the absolute path of self, without traversing symlinks.

Reference: https://stackoverflow.com/a/54817755/13482274

Gets the host-specific counterpart of self. If self is already host-specific, returns self directly.

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(),
);

Checks whether any of the component above self is readonly.

Checks whether any of the component refernces its parent.

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(),
);

Populate this item with given group config. The given group config is expected to be the group where this item belongs to.

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.

Implementors