Julio Biason
1 month ago
2 changed files with 63 additions and 18 deletions
@ -1,21 +1,39 @@ |
|||||||
|
use std::ffi::OsStr; |
||||||
use std::path::Path; |
use std::path::Path; |
||||||
|
|
||||||
use crate::diriter::DirIter; |
use diriter::Accept; |
||||||
|
|
||||||
|
use diriter::DirIter; |
||||||
|
|
||||||
mod diriter; |
mod diriter; |
||||||
|
|
||||||
|
struct AllFiles; |
||||||
|
impl Accept for AllFiles { |
||||||
|
fn accept_file(_: &Path) -> bool { |
||||||
|
true |
||||||
|
} |
||||||
|
fn accept_dir(_: &Path) -> bool { |
||||||
|
false |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
struct Sources; |
||||||
|
impl Accept for Sources { |
||||||
|
fn accept_dir(p: &Path) -> bool { |
||||||
|
p.file_name().unwrap() == OsStr::new("src") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
fn main() { |
fn main() { |
||||||
let mut all_iter = DirIter::new(&Path::new(".")).unwrap(); |
let mut all_iter = DirIter::<AllFiles>::new(&Path::new(".")).unwrap(); |
||||||
while let Some(path) = all_iter.next() { |
while let Some(path) = all_iter.next() { |
||||||
println!(">> {:?}", path); |
println!(">> {:?}", path); |
||||||
} |
} |
||||||
|
|
||||||
println!("-----------------------"); |
println!("{}", std::iter::repeat('-').take(80).collect::<String>()); |
||||||
|
|
||||||
let all_iter = DirIter::new(&Path::new(".")).unwrap(); |
let iter = DirIter::<Sources>::new(&Path::new(".")).unwrap(); |
||||||
for path in all_iter { |
for name in iter { |
||||||
println!(">>> {:?}", path); |
println!(">> {:?}", name); |
||||||
} |
} |
||||||
|
|
||||||
println!("Hello, world!"); |
|
||||||
} |
} |
||||||
|
Loading…
Reference in new issue