Struct testdir::NumberedDir

source ·
pub struct NumberedDir { /* private fields */ }
Expand description

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§

source§

impl NumberedDir

source

pub fn create( 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..

source

pub fn iterate(parent: impl AsRef<Path>, base: &str) -> Result<NumberedDirIter>

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.

source

pub fn path(&self) -> &Path

Returns the path of this numbered directory instance.

source

pub fn base(&self) -> &str

Returns the base of this NumberedDir instance.

The base is the name of the final NumberedDir::path component without the numbered suffix.

source

pub fn number(&self) -> u16

Returns the number suffix of this NumberedDir instance.

The number is the suffix of the final component of NumberedDir::path.

source

pub fn create_subdir(&self, rel_path: impl AsRef<Path>) -> Result<PathBuf>

Creates a subdirecotry within this numbered directory.

If the subdirectory already exists nothing is done.

There is no particular safety from malicious input, the numbered directory can be trivially escaped using the parent directory location: ../somewhere/else.

Trait Implementations§

source§

impl Clone for NumberedDir

source§

fn clone(&self) -> NumberedDir

Returns a copy 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 NumberedDir

source§

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

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

impl PartialEq for NumberedDir

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for NumberedDir

source§

impl StructuralEq for NumberedDir

source§

impl StructuralPartialEq for NumberedDir

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

§

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>,

§

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>,

§

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.