Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/walkdir.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Soo <jcsoo@agora.com>2017-06-29 17:21:28 +0300
committerAndrew Gallant <jamslam@gmail.com>2017-06-29 17:21:28 +0300
commit4e4c9c4f58a499acb0e38cf97377a4e0eec6a665 (patch)
treece335a05a32395bd3e81b01174434b4d38e35e34
parent532e56d2116a06e7f9f6f56d22dd0e5b507b1233 (diff)
add example for contents_first
Fixes #26
-rw-r--r--src/lib.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 008d8b2..ce5c76a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -316,6 +316,56 @@ impl WalkDir {
/// When `yes` is `true`, the iterator yields the contents of a directory
/// before yielding the directory itself. This is useful when, e.g. you
/// want to recursively delete a directory.
+ ///
+ /// # Example
+ ///
+ /// Assume the following directory tree:
+ ///
+ /// ```text
+ /// foo/
+ /// abc/
+ /// qrs
+ /// tuv
+ /// def/
+ /// ```
+ ///
+ /// With contents_first disabled (the default), the following code visits the
+ /// directory tree in depth-first order:
+ ///
+ /// ```rust,no_run
+ /// use walkdir::WalkDir;
+ ///
+ /// for entry in WalkDir::new("foo") {
+ /// let entry = entry.unwrap();
+ /// println!("{}", entry.path().display());
+ /// }
+ ///
+ /// // foo
+ /// // abc
+ /// // qrs
+ /// // tuv
+ /// // def
+ /// ```
+ ///
+ /// With contents_first enabled:
+ ///
+ /// ```rust,no_run
+ /// use walkdir::WalkDir;
+ ///
+ /// for entry in WalkDir::new("foo").contents_first(true) {
+ /// let entry = entry.unwrap();
+ /// println!("{}", entry.path().display());
+ /// }
+ ///
+ /// // qrs
+ /// // tuv
+ /// // abc
+ /// // def
+ /// // foo
+ /// ```
+
+
+
pub fn contents_first(mut self, yes: bool) -> Self {
self.opts.contents_first = yes;
self