DestinationDirectoryRule

Enum DestinationDirectoryRule 

Source
pub enum DestinationDirectoryRule {
    DisallowExisting,
    AllowEmpty,
    AllowNonEmpty {
        colliding_file_behaviour: CollidingFileBehaviour,
        colliding_subdirectory_behaviour: CollidingSubDirectoryBehaviour,
    },
}
Expand description

Specifies whether you allow the destination directory to exist before copying or moving files or directories into it.

If you allow the destination directory to exist, you can also specify whether it must be empty; if not, you may also specify how to behave for existing destination files and directories.

§Defaults

Default is implemented for this enum. The default value is DestinationDirectoryRule::AllowEmpty.

§Examples

If you want the associated directory copying or moving function to return an error if the provided destination directory already exists, use DestinationDirectoryRule::DisallowExisting. This is the strictest rule, requiring the destination to not exist.


If you at most want to copy into an empty destination directory, use DestinationDirectoryRule::AllowEmpty. This rule is slightly more relaxed than the previous one. It, however, does not require the destination directory to exist - it will be created if missing.


If the destination directory is allowed to exist and contain existing files or sub-directories, but you don’t want to overwrite any of the existing files, you can use the following rule:

let rules = DestinationDirectoryRule::AllowNonEmpty {
    colliding_file_behaviour: CollidingFileBehaviour::Abort,
    colliding_subdirectory_behaviour: CollidingSubDirectoryBehaviour::Continue,
};

This will create any missing destination sub-directories and ignore the ones that already exist, even if their counterparts also exist in the source directory. Also, this will still not overwrite existing destination files - it will effectively be a merge without overwrites.


If you want files to be overwritten, you may set the behaviour this way:

let rules = DestinationDirectoryRule::AllowNonEmpty {
    colliding_file_behaviour: CollidingFileBehaviour::Overwrite,
    colliding_subdirectory_behaviour: CollidingSubDirectoryBehaviour::Continue,
};

§A word of caution

Do not use DestinationDirectoryRule::AllowNonEmpty as a default unless you’re sure you are okay with merged directories.

If the destination directory already has some content, this would allow a copy or move that results in a destination directory with merged source and destination directory contents. Unless this is precisely what you’re after, you may want to avoid this option.

Variants§

§

DisallowExisting

Indicates the associated directory function should return an error, if the destination directory already exists.

§

AllowEmpty

Indicates the associated function should return an error, if the destination directory exists and is not empty.

This is the default.

§

AllowNonEmpty

Indicates that an existing (colliding) destination directory should not cause an error, even if non-empty.

Do not use this as a default if you’re not sure what rule to choose.

If the destination directory already has some content, this would allow a copy or move that results in a destination directory with merged source and destination directory contents. Unless this is precisely what you’re after, you may want to avoid this option.

Missing destination directories will always be created, regardless of the colliding_subdirectory_behaviour option. Setting it to CollidingSubDirectoryBehaviour::Continue simply means that if they already exist on the destination, they will not need to be created.

Fields

§colliding_file_behaviour: CollidingFileBehaviour

How to behave when encountering existing (colliding) destination files.

This option has no effect on existing destination files that don’t collide with the ones we’re copying or moving.

§colliding_subdirectory_behaviour: CollidingSubDirectoryBehaviour

How to behave when encountering existing (colliding) destination subdirectories.

This option has no effect on existing destination subdirectories that don’t collide with the ones we’re copying or moving.

Trait Implementations§

Source§

impl Clone for DestinationDirectoryRule

Source§

fn clone(&self) -> DestinationDirectoryRule

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DestinationDirectoryRule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DestinationDirectoryRule

Source§

fn default() -> Self

The default value for this struct is Self::AllowEmpty.

Source§

impl PartialEq for DestinationDirectoryRule

Source§

fn eq(&self, other: &DestinationDirectoryRule) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for DestinationDirectoryRule

Source§

impl Eq for DestinationDirectoryRule

Source§

impl StructuralPartialEq for DestinationDirectoryRule

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.