pub struct ListOption { /* private fields */ }
Implementations§
Source§impl ListOption
specify the list option
impl ListOption
specify the list option
pub fn new() -> Self
Sourcepub fn dir(&mut self, if_show: bool) -> &mut Self
pub fn dir(&mut self, if_show: bool) -> &mut Self
set if allow this option to show directories
Examples found in repository?
More examples
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}
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}
Sourcepub fn file(&mut self, if_show: bool) -> &mut Self
pub fn file(&mut self, if_show: bool) -> &mut Self
set if allow this option to show files
Examples found in repository?
More examples
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}
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}
set if allow this option to show hidden files
Examples found in repository?
More examples
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}
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}
set if allow this option to show unhidden files
Examples found in repository?
More examples
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}
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}
Sourcepub fn level(&mut self, level: usize) -> &mut Self
pub fn level(&mut self, level: usize) -> &mut Self
set the level of recursion while listing files in some path
Examples found in repository?
More examples
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}
Sourcepub fn recursive(&mut self, if_choose: bool) -> &mut Self
pub fn recursive(&mut self, if_choose: bool) -> &mut Self
set if allow this option to list recursively
Examples found in repository?
More examples
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}
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}
Sourcepub fn ext(&mut self, ext: &str) -> &mut Self
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
Sourcepub fn exts(&mut self, exts: Vec<&str>) -> &mut Self
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
Sourcepub fn suf(&mut self, suf: &str) -> &mut Self
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
Sourcepub fn sufs(&mut self, sufs: Vec<&str>) -> &mut Self
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?
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
impl ListOption
Source§impl ListOption
impl list functionality
impl ListOption
impl list functionality
Sourcepub fn list<S>(&self, path: &S) -> Vec<String>
pub fn list<S>(&self, path: &S) -> Vec<String>
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?
More examples
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}
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}
Trait Implementations§
Source§impl Clone for ListOption
impl Clone for ListOption
Source§fn clone(&self) -> ListOption
fn clone(&self) -> ListOption
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more