diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 1dccb053f900e..f36dfbf3009d5 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1773,9 +1773,10 @@ impl Vec { } } - /// Appends an element if there is sufficient spare capacity, otherwise the element is returned. + /// Appends an element if there is sufficient spare capacity, otherwise an error is returned + /// with the element. /// - /// Unlike [`push`] method will not reallocate when there's insufficient capacity. + /// Unlike [`push`] this method will not reallocate when there's insufficient capacity. /// The caller should use [`reserve`] or [`try_reserve`] to ensure that there is enough capacity. /// /// [`push`]: Vec::push @@ -1784,13 +1785,13 @@ impl Vec { /// /// # Examples /// - /// A manual, panic-free alternative to FromIterator + /// A manual, panic-free alternative to [`FromIterator`]: /// /// ``` - /// #![feature(vec_push_within_capacity, try_reserve)] + /// #![feature(vec_push_within_capacity)] /// /// use std::collections::TryReserveError; - /// fn from_iter(iter: impl Iterator) -> Result, TryReserveError> { + /// fn from_iter_fallible(iter: impl Iterator) -> Result, TryReserveError> { /// let mut vec = Vec::new(); /// for value in iter { /// if let Err(value) = vec.push_within_capacity(value) { @@ -1801,10 +1802,10 @@ impl Vec { /// } /// Ok(vec) /// } - /// # from_iter(0..100).expect("please insert more memory"); + /// assert_eq!(from_iter_fallible(0..100), Ok(Vec::from_iter(0..100))); /// ``` #[inline] - #[unstable(feature = "vec_push_within_capacity", issue = "none")] + #[unstable(feature = "vec_push_within_capacity", issue = "100486")] pub fn push_within_capacity(&mut self, value: T) -> Result<(), T> { if self.len == self.buf.capacity() { return Err(value);