Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the examples in String and VecDeque::retain #87574

Merged
merged 1 commit into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// assert_eq!(buf, [2, 4]);
/// ```
///
/// The exact order may be useful for tracking external state, like an index.
/// Because the elements are visited exactly once in the original order,
/// external state may be used to decide which elements to keep.
///
/// ```
/// use std::collections::VecDeque;
Expand All @@ -2116,8 +2117,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// buf.extend(1..6);
///
/// let keep = [false, true, true, false, true];
/// let mut i = 0;
/// buf.retain(|_| (keep[i], i += 1).0);
/// let mut iter = keep.iter();
/// buf.retain(|_| *iter.next().unwrap());
/// assert_eq!(buf, [2, 3, 5]);
/// ```
#[stable(feature = "vec_deque_retain", since = "1.4.0")]
Expand Down
7 changes: 4 additions & 3 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1350,13 +1350,14 @@ impl String {
/// assert_eq!(s, "foobar");
/// ```
///
/// The exact order may be useful for tracking external state, like an index.
/// Because the elements are visited exactly once in the original order,
/// external state may be used to decide which elements to keep.
///
/// ```
/// let mut s = String::from("abcde");
/// let keep = [false, true, true, false, true];
/// let mut i = 0;
/// s.retain(|_| (keep[i], i += 1).0);
/// let mut iter = keep.iter();
/// s.retain(|_| *iter.next().unwrap());
/// assert_eq!(s, "bce");
/// ```
#[inline]
Expand Down