WalkerRule

Struct WalkerRule 

Source
pub struct WalkerRule {
    pub name: &'static str,
    pub description: Option<String>,
    pub only_for: Option<WalkerItemType>,
    pub matches: Box<dyn Fn(&Path, &WalkerConfig, &Path) -> bool>,
    pub action: Box<dyn Fn(&Path, &WalkerConfig, &Path) -> Result<WalkerRuleResult, Error>>,
}
Expand description

Walker rule (run on individual items)

use rebackup::config::*;

let rule = WalkerRule {
    // Name of the rule
    name: "nomedia",

    // Optional description of the rule
    description: None,

    // The type of items the rule applies to (`None` for all)
    only_for: Some(WalkerItemType::Directory),

    // Check if the rule would match a specific item
    matches: Box::new(|path, _, _| path.join(".nomedia").is_file()),

    // Apply the rule to determine what to do
    action: Box::new(|_, _, _| Ok(WalkerRuleResult::ExcludeItem)),
};

Fields§

§name: &'static str

Rule’s name

§description: Option<String>

Rule’s optional description

§only_for: Option<WalkerItemType>

Indicate if the rule should only be applied on a specific type of filesystem items

§matches: Box<dyn Fn(&Path, &WalkerConfig, &Path) -> bool>

Predicate to indicate if the rule should be run on a specific item. The checking should be as fast as possible, the goal of this callback being to not having as much overhad as action.

Arguments are the item’s absolute path, the walker’s configuration, as well as the source directory (absolute, canonicalized)

§action: Box<dyn Fn(&Path, &WalkerConfig, &Path) -> Result<WalkerRuleResult, Error>>

Action to perform when the rule is applies on a specific item

Arguments are the item’s absolute path, the walker’s configuration, as well as the source directory (absolute, canonicalized)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.