diff options
author | Jonathan Soo <jcsoo@agora.com> | 2017-06-29 17:21:28 +0300 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2017-06-29 17:21:28 +0300 |
commit | 4e4c9c4f58a499acb0e38cf97377a4e0eec6a665 (patch) | |
tree | ce335a05a32395bd3e81b01174434b4d38e35e34 | |
parent | 532e56d2116a06e7f9f6f56d22dd0e5b507b1233 (diff) |
add example for contents_first
Fixes #26
-rw-r--r-- | src/lib.rs | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -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 |