[−][src]Struct testdir::NumberedDir
A sequentially numbered directory.
This struct represents a directory is a sequentially numbered list of directories. It allows creating the next sequential directory safely across processes or threads without any coordination as well as cleanup of older directories.
The directory has a parent directory in which the numbered directory is created, as well as a base which is used as the directory name to which to affix the number.
Implementations
impl NumberedDir
[src]
pub fn create(
parent: impl AsRef<Path>,
base: &str,
count: NonZeroU8
) -> Result<Self>
[src]
parent: impl AsRef<Path>,
base: &str,
count: NonZeroU8
) -> Result<Self>
Creates the next sequential numbered directory.
The directory will be created inside parent
and will start with the name given in
base
to which the next available number is suffixed.
If there are concurrent directories being created this will retry incrementing the number up to 16 times before giving up.
The count
specifies the total number of directories to leave in place, including
the newly created directory. Other previous directories with all their files and
subdirectories are recursively removed. Care is taken to avoid removing new
directories concurrently created by parallel invocations in other threads or
processes..
pub fn iterate(parent: impl AsRef<Path>, base: &str) -> Result<NumberedDirIter>
[src]
Returns an iterator over all NumberedDir
entries in a parent directory.
This iterator can be used to get access to existing NumberedDir
directories
without creating a new one.
pub fn path(&self) -> &Path
[src]
Returns the path of this numbered directory instance.
pub fn base(&self) -> &str
[src]
Returns the base of this NumberedDir
instance.
The base is the name of the final NumberedDir::path
component without the
numbered suffix.
pub fn number(&self) -> u16
[src]
Returns the number suffix of this NumberedDir
instance.
The number is the suffix of the final component of NumberedDir::path
.
pub fn create_subdir(&self, rel_path: impl AsRef<Path>) -> Result<PathBuf>
[src]
Creates a new subdirecotry within this numbered directory.
This function will always create a new subdirecotry, if such a directory already exists the last component will get an incremental number suffix.
Limitations
Only up to u16::MAX
numbered suffixes are created so this is the maximum number
of "identically" named directories that can be created. Creating so many
directories will become expensive however as the suffixes are linearly searched for
the next available suffix. This is not meant for a high number of conflicting
subdirectories, if this is required ensure the rel_path
passed in already avoids
conflicts.
There is no particular safety from malicious input, the numbered directory can be
trivially escaped using the parent directory location: ../somewhere/else
.
Trait Implementations
impl Clone for NumberedDir
[src]
pub fn clone(&self) -> NumberedDir
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for NumberedDir
[src]
impl Eq for NumberedDir
[src]
impl PartialEq<NumberedDir> for NumberedDir
[src]
pub fn eq(&self, other: &NumberedDir) -> bool
[src]
pub fn ne(&self, other: &NumberedDir) -> bool
[src]
impl StructuralEq for NumberedDir
[src]
impl StructuralPartialEq for NumberedDir
[src]
Auto Trait Implementations
impl RefUnwindSafe for NumberedDir
[src]
impl Send for NumberedDir
[src]
impl Sync for NumberedDir
[src]
impl Unpin for NumberedDir
[src]
impl UnwindSafe for NumberedDir
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,