Struct lrg::Lrg

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

The main struct for searching for files by size. Constructed using new, passing in a path and options.

Implementations§

Creates a new Lrg with options and at the given path.

Examples
let path = Path::new(".");
let lrg = Lrg::new(path, &LrgOptions::default());

To use custom options, just supply a LrgOptions struct.

To only search the base directoy, using the other default options:

let path = Path::new(".");
let opts = LrgOptions {
    min_depth: 1,
    ..LrgOptions::default()
};

Sorts the lrg object entries, and returns the lrg object.

Examples

To get the largest files first:

let path = Path::new(".");
let mut lrg = Lrg::new(path, &LrgOptions::default());
lrg.sort_by(&SortBy::Descending);

Sorts the lrg object entries by a custom sort function, and returns the lrg object.

Examples

To search by creation date:

let path = Path::new("./another/path");
let mut lrg = Lrg::new(path, &LrgOptions::default());
lrg.sort_by_custom(|a: &DirEntry, b: &DirEntry| {
    // Create custom function to get creation date of a `DirEntry`
    let creation_date = |x: &DirEntry| {
        match x.metadata() {
            Ok(meta) => {
                match meta.created() {
                    Ok(created) => created,
                    Err(_) => std::time::SystemTime::UNIX_EPOCH,
                }
            },
            // Default to UNIX epoch
            Err(_) => std::time::SystemTime::UNIX_EPOCH,
        }
    };
    //Make comparison
    creation_date(a).cmp(&creation_date(b))
});
// Get entries
let entries: Vec<DirEntry> = lrg.get_entries();

Sorts the lrg object entries by ascending file size, and returns the lrg object.

Examples
let path = Path::new("./another/path");
let mut lrg: Lrg = Lrg::new(path, &LrgOptions::default());
let entries = lrg.sort_ascending().get_entries();

Sorts the lrg object entries by descending file size, and returns the lrg object.

Examples
let path = Path::new("./another/path");
let mut lrg: Lrg = Lrg::new(path, &LrgOptions::default());
let entries = lrg.sort_descending().get_entries();

Gets the entries from the Lrg object.

Examples
let path = Path::new("./another/path");
let mut lrg: Lrg = Lrg::new(path, &LrgOptions::default());
let entries = lrg.sort_ascending().get_entries();

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.