about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKriskras99 <github@kriskras99.nl>2024-04-10 13:43:36 +0200
committerGitHub <noreply@github.com>2024-04-10 13:43:36 +0200
commit6b0d3663c1be68a0f5a619c00e946b0754d7c3a8 (patch)
tree856bb803e77e2cb2d4af5d4ad64965215d4f90a5
parentbc8ad6a41eb8ba30787cfae159f8d778fcb5b2e7 (diff)
downloadrust-6b0d3663c1be68a0f5a619c00e946b0754d7c3a8.tar.gz
rust-6b0d3663c1be68a0f5a619c00e946b0754d7c3a8.zip
Rework Path::ancestors documentation to remove unwraps
If you take a quick glance at the documentation for Path::ancestors, the unwraps take the natural focus. Potentially indicating that ancestors might panic.
In the reworked version I've also moved the link with parent returning None and that the iterator will always yield &self to before the yield examples.
-rw-r--r--library/std/src/path.rs7
1 files changed, 3 insertions, 4 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs
index ba86b73f3a8..5f43d63bf84 100644
--- a/library/std/src/path.rs
+++ b/library/std/src/path.rs
@@ -2278,10 +2278,9 @@ impl Path {
     /// Produces an iterator over `Path` and its ancestors.
     ///
     /// The iterator will yield the `Path` that is returned if the [`parent`] method is used zero
-    /// or more times. That means, the iterator will yield `&self`, `&self.parent().unwrap()`,
-    /// `&self.parent().unwrap().parent().unwrap()` and so on. If the [`parent`] method returns
-    /// [`None`], the iterator will do likewise. The iterator will always yield at least one value,
-    /// namely `&self`.
+    /// or more times. If the [`parent`] method returns [`None`], the iterator will do likewise.
+    /// The iterator will always yield at least one value, namely `Some(&self)`. Next it will yield
+    /// `&self.parent()`, `&self.parent().and_then(Path::parent)` and so on.
     ///
     /// # Examples
     ///