Skip to content

Commit ebecd79

Browse files
Update library/alloc/src/vec/mod.rs with suggestion
Co-authored-by: Ibraheem Ahmed <[email protected]>
1 parent d309147 commit ebecd79

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

library/alloc/src/vec/mod.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,28 +2574,12 @@ impl<T, A: Allocator> Vec<T, A> {
25742574
/// ```
25752575
/// #![feature(push_mut)]
25762576
///
2577-
/// # #[allow(unused)]
2578-
/// #[derive(PartialEq, Eq, Debug)]
2579-
/// struct Item { identifier: &'static str, count: usize }
2580-
///
2581-
/// impl Default for Item {
2582-
/// fn default() -> Self {
2583-
/// return Self { identifier: "stone", count: 64 }
2584-
/// }
2585-
/// }
2586-
///
2587-
/// let mut items = vec![];
2588-
///
2589-
/// // We can mutate the just-pushed value without having to fetch it again
2590-
/// for count in [15, 35, 61] {
2591-
/// let item = items.push_mut(Item::default());
2592-
/// item.count = count;
2593-
/// }
2594-
///
2595-
/// assert_eq!(
2596-
/// items,
2597-
/// [Item { identifier: "stone", count: 15 }, Item { identifier: "stone", count: 35 }, Item { identifier: "stone", count: 61 }]
2598-
/// );
2577+
/// let mut vec = vec![1, 2];
2578+
/// let last = vec.push(3);
2579+
/// assert_eq!(vec, [1, 2, 3]);
2580+
/// *last = 4;
2581+
/// assert_eq!(vec, [1, 2, 4]);
2582+
/// ```
25992583
/// ```
26002584
///
26012585
/// # Time complexity

0 commit comments

Comments
 (0)