diff options
| author | Corey Farwell <coreyf@rwell.org> | 2016-08-30 09:29:22 -0400 |
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2016-08-30 19:57:20 -0400 |
| commit | 268b3f58184cc7efa8196a28cccffcc01a5d61ac (patch) | |
| tree | 64e3ccb4e9ecc4873f0ecd078fe0024f61063fd6 /src/libstd/path.rs | |
| parent | f48d3859bc90e6e8a2e5455845b13d55bb8720ab (diff) | |
| download | rust-268b3f58184cc7efa8196a28cccffcc01a5d61ac.tar.gz rust-268b3f58184cc7efa8196a28cccffcc01a5d61ac.zip | |
Implement `Debug` for `std::path::Iter`.
Diffstat (limited to 'src/libstd/path.rs')
| -rw-r--r-- | src/libstd/path.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 791b7b2288d..dbf17b3c813 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -837,6 +837,25 @@ impl<'a> AsRef<OsStr> for Components<'a> { } } +#[stable(feature = "path_iter_debug", since = "1.13.0")] +impl<'a> fmt::Debug for Iter<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + struct DebugHelper<'a>(&'a Path); + + impl<'a> fmt::Debug for DebugHelper<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_list() + .entries(self.0.iter()) + .finish() + } + } + + f.debug_tuple("Iter") + .field(&DebugHelper(self.as_path())) + .finish() + } +} + impl<'a> Iter<'a> { /// Extracts a slice corresponding to the portion of the path remaining for iteration. #[stable(feature = "rust1", since = "1.0.0")] @@ -3523,4 +3542,26 @@ mod tests { let actual = format!("{:?}", components); assert_eq!(expected, actual); } + + #[cfg(unix)] + #[test] + fn test_iter_debug() { + let path = Path::new("/tmp"); + + let mut iter = path.iter(); + + let expected = "Iter([\"/\", \"tmp\"])"; + let actual = format!("{:?}", iter); + assert_eq!(expected, actual); + + let _ = iter.next().unwrap(); + let expected = "Iter([\"tmp\"])"; + let actual = format!("{:?}", iter); + assert_eq!(expected, actual); + + let _ = iter.next().unwrap(); + let expected = "Iter([])"; + let actual = format!("{:?}", iter); + assert_eq!(expected, actual); + } } |
