fs::walk_dir example without unstable features
The current version of the example won't compile due to unstable features. This is an attempt to fix that, at the cost of slightly more verbose code.
This commit is contained in:
parent
0d707d15f6
commit
b6e755df66
1 changed files with 5 additions and 6 deletions
|
|
@ -1099,20 +1099,19 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #![feature(path_ext)]
|
||||
/// use std::io;
|
||||
/// use std::fs::{self, PathExt, DirEntry};
|
||||
/// use std::fs::{self, DirEntry};
|
||||
/// use std::path::Path;
|
||||
///
|
||||
/// // one possible implementation of fs::walk_dir only visiting files
|
||||
/// fn visit_dirs(dir: &Path, cb: &mut FnMut(DirEntry)) -> io::Result<()> {
|
||||
/// if dir.is_dir() {
|
||||
/// fn visit_dirs(dir: &Path, cb: &Fn(&DirEntry)) -> io::Result<()> {
|
||||
/// if try!(fs::metadata(dir)).is_dir() {
|
||||
/// for entry in try!(fs::read_dir(dir)) {
|
||||
/// let entry = try!(entry);
|
||||
/// if entry.path().is_dir() {
|
||||
/// if try!(fs::metadata(entry.path())).is_dir() {
|
||||
/// try!(visit_dirs(&entry.path(), cb));
|
||||
/// } else {
|
||||
/// cb(entry);
|
||||
/// cb(&entry);
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue