Struct FileDeclutter

Source
pub struct FileDeclutter;
Expand description

Entry point for creating decluttering iterators or computing decluttered paths.

Implementations§

Source§

impl FileDeclutter

Source

pub fn new_from_iter( iter: impl Iterator<Item = impl Into<PathBuf>>, ) -> FileDeclutterIterator<impl Iterator<Item = PathBuf>>

Creates a FileDeclutterIterator from an arbitrary iterator over file paths.

§Examples
let files = vec!["13.txt", "23.txt"];
let files_decluttered = file_declutter::FileDeclutter::new_from_iter(files.into_iter())
    .levels(1)
    .collect::<Vec<_>>();

let files_expected = vec![
    (PathBuf::from("13.txt"), PathBuf::from("1/13.txt")),
    (PathBuf::from("23.txt"), PathBuf::from("2/23.txt")),
];

assert_eq!(files_expected, files_decluttered);
Source

pub fn new_from_path( base: impl Into<PathBuf>, ) -> FileDeclutterIterator<impl Iterator<Item = PathBuf>>

Creates a FileDeclutterIterator by recursively collecting all files under a given directory and setting this directory as the base.

§Examples
let files_decluttered = file_declutter::FileDeclutter::new_from_path("/tmp/path")
    .levels(1)
    .collect::<Vec<_>>();

// If the specified directory contains the files 13.txt and 23.txt, the following tuples
// will be produced:
let files_expected = vec![
    (PathBuf::from("13.txt"), PathBuf::from("1/13.txt")),
    (PathBuf::from("23.txt"), PathBuf::from("2/23.txt")),
];

assert_eq!(files_expected, files_decluttered);
Source

pub fn oneshot(file: impl Into<PathBuf>, levels: usize) -> PathBuf

Computes the decluttered path of a single file without moving it.

§Arguments
  • file: Path to the input file.
  • levels: Number of subdirectory levels to use.
§Returns

A PathBuf representing the target decluttered location.

§Examples
let file = "123456.txt";
let file_decluttered = file_declutter::FileDeclutter::oneshot(file, 3);

let file_expected = PathBuf::from("1/2/3/123456.txt");

assert_eq!(file_expected, file_decluttered);

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.