@@ -1773,9 +1773,10 @@ impl<T, A: Allocator> Vec<T, A> {
17731773 }
17741774 }
17751775
1776- /// Appends an element if there is sufficient spare capacity, otherwise the element is returned.
1776+ /// Appends an element if there is sufficient spare capacity, otherwise an error is returned
1777+ /// with the element.
17771778 ///
1778- /// Unlike [`push`] method will not reallocate when there's insufficient capacity.
1779+ /// Unlike [`push`] this method will not reallocate when there's insufficient capacity.
17791780 /// The caller should use [`reserve`] or [`try_reserve`] to ensure that there is enough capacity.
17801781 ///
17811782 /// [`push`]: Vec::push
@@ -1784,13 +1785,13 @@ impl<T, A: Allocator> Vec<T, A> {
17841785 ///
17851786 /// # Examples
17861787 ///
1787- /// A manual, panic-free alternative to FromIterator
1788+ /// A manual, panic-free alternative to [` FromIterator`]:
17881789 ///
17891790 /// ```
1790- /// #![feature(vec_push_within_capacity, try_reserve )]
1791+ /// #![feature(vec_push_within_capacity)]
17911792 ///
17921793 /// use std::collections::TryReserveError;
1793- /// fn from_iter <T>(iter: impl Iterator<Item=T>) -> Result<Vec<T>, TryReserveError> {
1794+ /// fn from_iter_fallible <T>(iter: impl Iterator<Item=T>) -> Result<Vec<T>, TryReserveError> {
17941795 /// let mut vec = Vec::new();
17951796 /// for value in iter {
17961797 /// if let Err(value) = vec.push_within_capacity(value) {
@@ -1801,10 +1802,10 @@ impl<T, A: Allocator> Vec<T, A> {
18011802 /// }
18021803 /// Ok(vec)
18031804 /// }
1804- /// # from_iter(0..100).expect("please insert more memory" );
1805+ /// assert_eq!(from_iter_fallible(0..100), Ok(Vec:: from_iter(0..100)) );
18051806 /// ```
18061807 #[ inline]
1807- #[ unstable( feature = "vec_push_within_capacity" , issue = "none " ) ]
1808+ #[ unstable( feature = "vec_push_within_capacity" , issue = "100486 " ) ]
18081809 pub fn push_within_capacity ( & mut self , value : T ) -> Result < ( ) , T > {
18091810 if self . len == self . buf . capacity ( ) {
18101811 return Err ( value) ;
0 commit comments