1pub mod ignore;
2
3use std::io;
4
5use io::Write;
6
7use std::ffi::OsStr;
8
9use std::fs::FileType;
10use std::fs::Metadata;
11
12use std::path::Path;
13use std::path::PathBuf;
14
15pub trait Entry {
16 fn path(&self) -> &Path;
17 fn into_path(self) -> PathBuf;
18 fn is_symlink(&self) -> bool;
19 fn metadata(&self) -> Result<Metadata, io::Error>;
20 fn file_type(&self) -> Option<FileType>;
21 fn file_name(&self) -> &OsStr;
22 fn depth(&self) -> usize;
23 fn ino(&self) -> Option<u64>;
24}
25
26pub fn write_dirents<I, W, S, E>(mut wtr: W, ser: S) -> impl FnMut(I) -> Result<(), io::Error>
27where
28 W: Write,
29 S: Fn(&E, &mut Vec<u8>) -> Result<(), io::Error>,
30 E: Entry,
31 I: Iterator<Item = Result<E, io::Error>>,
32{
33 move |dirents: I| {
34 let mut buf: Vec<u8> = vec![];
35 for rdirent in dirents {
36 let dirent: E = rdirent?;
37 buf.clear();
38 ser(&dirent, &mut buf)?;
39 wtr.write_all(&buf)?;
40 }
41 wtr.flush()
42 }
43}