From 4e4c9c4f58a499acb0e38cf97377a4e0eec6a665 Mon Sep 17 00:00:00 2001 From: Jonathan Soo Date: Thu, 29 Jun 2017 10:21:28 -0400 Subject: add example for contents_first Fixes #26 --- src/lib.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) 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 -- cgit v1.2.3