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: CollidingFileBehaviourHow 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: CollidingSubDirectoryBehaviourHow 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
impl Clone for DestinationDirectoryRule
Source§fn clone(&self) -> DestinationDirectoryRule
fn clone(&self) -> DestinationDirectoryRule
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DestinationDirectoryRule
impl Debug for DestinationDirectoryRule
Source§impl Default for DestinationDirectoryRule
impl Default for DestinationDirectoryRule
Source§fn default() -> Self
fn default() -> Self
The default value for this struct is Self::AllowEmpty.