Struct ListOption

Source
pub struct ListOption { /* private fields */ }

Implementations§

Source§

impl ListOption

specify the list option

Source

pub fn new() -> Self

Source

pub fn dir(&mut self, if_show: bool) -> &mut Self

set if allow this option to show directories

Examples found in repository?
examples/list_unexisted_dir.rs (line 4)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(true)
6        .hidden(false)
7        .unhidden(true)
8        .recursive(true)
9        .level(1)
10        .list("unexisted_dir"));
11}
More examples
Hide additional examples
examples/list_all_rs.rs (line 5)
1fn main() {
2    use ls_option::*;
3    let fs = ListOption::default()
4        .file(true)
5        .dir(false)
6        .unhidden(true)
7        .hidden(false)
8        .recursive(true)
9        .sufs(vec![".rs"])
10        .list(".");
11    dbg!(fs);
12}
examples/list_all_hidden_dir.rs (line 4)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(false)
6        .hidden(true)
7        .unhidden(false)
8        .hidden(true)
9        .recursive(false)
10        .level(1)
11        .list("."));
12}
Source

pub fn file(&mut self, if_show: bool) -> &mut Self

set if allow this option to show files

Examples found in repository?
examples/list_unexisted_dir.rs (line 5)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(true)
6        .hidden(false)
7        .unhidden(true)
8        .recursive(true)
9        .level(1)
10        .list("unexisted_dir"));
11}
More examples
Hide additional examples
examples/list_all_rs.rs (line 4)
1fn main() {
2    use ls_option::*;
3    let fs = ListOption::default()
4        .file(true)
5        .dir(false)
6        .unhidden(true)
7        .hidden(false)
8        .recursive(true)
9        .sufs(vec![".rs"])
10        .list(".");
11    dbg!(fs);
12}
examples/list_all_hidden_dir.rs (line 5)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(false)
6        .hidden(true)
7        .unhidden(false)
8        .hidden(true)
9        .recursive(false)
10        .level(1)
11        .list("."));
12}
Source

pub fn hidden(&mut self, if_show: bool) -> &mut Self

set if allow this option to show hidden files

Examples found in repository?
examples/list_unexisted_dir.rs (line 6)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(true)
6        .hidden(false)
7        .unhidden(true)
8        .recursive(true)
9        .level(1)
10        .list("unexisted_dir"));
11}
More examples
Hide additional examples
examples/list_all_rs.rs (line 7)
1fn main() {
2    use ls_option::*;
3    let fs = ListOption::default()
4        .file(true)
5        .dir(false)
6        .unhidden(true)
7        .hidden(false)
8        .recursive(true)
9        .sufs(vec![".rs"])
10        .list(".");
11    dbg!(fs);
12}
examples/list_all_hidden_dir.rs (line 6)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(false)
6        .hidden(true)
7        .unhidden(false)
8        .hidden(true)
9        .recursive(false)
10        .level(1)
11        .list("."));
12}
Source

pub fn unhidden(&mut self, if_show: bool) -> &mut Self

set if allow this option to show unhidden files

Examples found in repository?
examples/list_unexisted_dir.rs (line 7)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(true)
6        .hidden(false)
7        .unhidden(true)
8        .recursive(true)
9        .level(1)
10        .list("unexisted_dir"));
11}
More examples
Hide additional examples
examples/list_all_rs.rs (line 6)
1fn main() {
2    use ls_option::*;
3    let fs = ListOption::default()
4        .file(true)
5        .dir(false)
6        .unhidden(true)
7        .hidden(false)
8        .recursive(true)
9        .sufs(vec![".rs"])
10        .list(".");
11    dbg!(fs);
12}
examples/list_all_hidden_dir.rs (line 7)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(false)
6        .hidden(true)
7        .unhidden(false)
8        .hidden(true)
9        .recursive(false)
10        .level(1)
11        .list("."));
12}
Source

pub fn level(&mut self, level: usize) -> &mut Self

set the level of recursion while listing files in some path

Examples found in repository?
examples/list_unexisted_dir.rs (line 9)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(true)
6        .hidden(false)
7        .unhidden(true)
8        .recursive(true)
9        .level(1)
10        .list("unexisted_dir"));
11}
More examples
Hide additional examples
examples/list_all_hidden_dir.rs (line 10)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(false)
6        .hidden(true)
7        .unhidden(false)
8        .hidden(true)
9        .recursive(false)
10        .level(1)
11        .list("."));
12}
Source

pub fn recursive(&mut self, if_choose: bool) -> &mut Self

set if allow this option to list recursively

Examples found in repository?
examples/list_unexisted_dir.rs (line 8)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(true)
6        .hidden(false)
7        .unhidden(true)
8        .recursive(true)
9        .level(1)
10        .list("unexisted_dir"));
11}
More examples
Hide additional examples
examples/list_all_rs.rs (line 8)
1fn main() {
2    use ls_option::*;
3    let fs = ListOption::default()
4        .file(true)
5        .dir(false)
6        .unhidden(true)
7        .hidden(false)
8        .recursive(true)
9        .sufs(vec![".rs"])
10        .list(".");
11    dbg!(fs);
12}
examples/list_all_hidden_dir.rs (line 9)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(false)
6        .hidden(true)
7        .unhidden(false)
8        .hidden(true)
9        .recursive(false)
10        .level(1)
11        .list("."));
12}
Source

pub fn ext(&mut self, ext: &str) -> &mut Self

add one ext to the list of allowed extensions

only files with one of these extensions will be listed

e.g. ext(“rs”) will allow files with .rs extension to be listed

e.g. ext(“rs”).ext(“toml”) will allow files with .rs and .toml extensions to be listed

Source

pub fn exts(&mut self, exts: Vec<&str>) -> &mut Self

add multiple exts to the list of allowed extensions

only files with one of these extensions will be listed

but this function will shadow the previous sufs

e.g. exts(vec![“rs”, “toml”]) will allow files with .rs and .toml extensions to be listed

e.g. exts(vec![“rs”]).exts(vec![“toml”]) will only allow files with .toml extensions to be listed

Source

pub fn suf(&mut self, suf: &str) -> &mut Self

add one suf to the list of allowed suffixes, only files with one of these suffixes will be listed

e.g. suf(“rs”) will allow files with rs suffix to be listed

notice that exts function will shadow the previous sufs

e.g. suf(“.rs”).ext(“toml”) will only allow files with .rs and .toml extensions to be listed

e.g. suf(“.rs”).suf(“.toml”) will only allow files with .toml extensions to be listed

e.g. suf(“rs”).exts(vec![“toml”]) will only allow files with .toml extensions to be listed

Source

pub fn sufs(&mut self, sufs: Vec<&str>) -> &mut Self

add multiple sufs to the list of allowed suffixes

only files with one of these suffixes will be listed

but this function will shadow the previous sufs

e.g. sufs(vec![“rs”, “toml”]) will allow files with rs and toml suffixes to be listed

e.g. sufs(vec![“.rs”]).sufs(vec![“.toml”]) will only allow files with .toml extensions to be listed

e.g. sufs(vec![“.rs”]).ext(“toml”) will allow files with .rs or .toml extension to be listed

e.g. sufs(vec![“rs”]).exts(vec![“toml”]) will only allow files with .toml extensions to be listed

Examples found in repository?
examples/list_all_rs.rs (line 9)
1fn main() {
2    use ls_option::*;
3    let fs = ListOption::default()
4        .file(true)
5        .dir(false)
6        .unhidden(true)
7        .hidden(false)
8        .recursive(true)
9        .sufs(vec![".rs"])
10        .list(".");
11    dbg!(fs);
12}
Source§

impl ListOption

Source

pub fn only_dir(&mut self) -> &mut Self

Source

pub fn only_file(&mut self) -> &mut Self

Source

pub fn only_hidden(&mut self) -> &mut Self

Source

pub fn only_unhidden(&mut self) -> &mut Self

Source§

impl ListOption

impl list functionality

Source

pub fn list<S>(&self, path: &S) -> Vec<String>
where S: AsRef<OsStr> + ?Sized,

Lists the files and directories at the given path according to the options set in the ListOption

if the path is a file, it will be listed if it matches the options set in the ListOption

if the path is a directory, all files and directories in it will be listed if they match the options set in the ListOption

Examples found in repository?
examples/list_unexisted_dir.rs (line 10)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(true)
6        .hidden(false)
7        .unhidden(true)
8        .recursive(true)
9        .level(1)
10        .list("unexisted_dir"));
11}
More examples
Hide additional examples
examples/list_all_rs.rs (line 10)
1fn main() {
2    use ls_option::*;
3    let fs = ListOption::default()
4        .file(true)
5        .dir(false)
6        .unhidden(true)
7        .hidden(false)
8        .recursive(true)
9        .sufs(vec![".rs"])
10        .list(".");
11    dbg!(fs);
12}
examples/list_all_hidden_dir.rs (line 11)
1fn main() {
2    use ls_option::ListOption;
3    dbg!(ListOption::default()
4        .dir(true)
5        .file(false)
6        .hidden(true)
7        .unhidden(false)
8        .hidden(true)
9        .recursive(false)
10        .level(1)
11        .list("."));
12}
Source

pub fn would_show<S>(&self, path: &S) -> bool
where S: AsRef<OsStr> + ?Sized,

check if the path would be shown according to the options set in the ListOption

Trait Implementations§

Source§

impl Clone for ListOption

Source§

fn clone(&self) -> ListOption

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 ListOption

Source§

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

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

impl Default for ListOption

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

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.