Skip to content

Commit b763436

Browse files
authored
Rollup merge of rust-lang#77017 - GuillaumeGomez:vec-missing-examples-iter, r=Dylan-DPC
Add missing examples on Vec iter types r? @Dylan-DPC
2 parents bcdbe79 + 143557e commit b763436

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

library/alloc/src/vec.rs

+31
Original file line numberDiff line numberDiff line change
@@ -2849,6 +2849,13 @@ where
28492849
///
28502850
/// This `struct` is created by the `into_iter` method on [`Vec`] (provided
28512851
/// by the [`IntoIterator`] trait).
2852+
///
2853+
/// # Example
2854+
///
2855+
/// ```
2856+
/// let v = vec![0, 1, 2];
2857+
/// let iter: std::vec::IntoIter<_> = v.into_iter();
2858+
/// ```
28522859
#[stable(feature = "rust1", since = "1.0.0")]
28532860
pub struct IntoIter<T> {
28542861
buf: NonNull<T>,
@@ -3092,6 +3099,13 @@ impl<T> AsIntoIter for IntoIter<T> {
30923099
///
30933100
/// This `struct` is created by [`Vec::drain`].
30943101
/// See its documentation for more.
3102+
///
3103+
/// # Example
3104+
///
3105+
/// ```
3106+
/// let mut v = vec![0, 1, 2];
3107+
/// let iter: std::vec::Drain<_> = v.drain(..);
3108+
/// ```
30953109
#[stable(feature = "drain", since = "1.6.0")]
30963110
pub struct Drain<'a, T: 'a> {
30973111
/// Index of tail to preserve
@@ -3221,6 +3235,14 @@ impl<T> FusedIterator for Drain<'_, T> {}
32213235
///
32223236
/// This struct is created by [`Vec::splice()`].
32233237
/// See its documentation for more.
3238+
///
3239+
/// # Example
3240+
///
3241+
/// ```
3242+
/// let mut v = vec![0, 1, 2];
3243+
/// let new = [7, 8];
3244+
/// let iter: std::vec::Splice<_> = v.splice(1.., new.iter().cloned());
3245+
/// ```
32243246
#[derive(Debug)]
32253247
#[stable(feature = "vec_splice", since = "1.21.0")]
32263248
pub struct Splice<'a, I: Iterator + 'a> {
@@ -3337,6 +3359,15 @@ impl<T> Drain<'_, T> {
33373359
///
33383360
/// This struct is created by [`Vec::drain_filter`].
33393361
/// See its documentation for more.
3362+
///
3363+
/// # Example
3364+
///
3365+
/// ```
3366+
/// #![feature(drain_filter)]
3367+
///
3368+
/// let mut v = vec![0, 1, 2];
3369+
/// let iter: std::vec::DrainFilter<_, _> = v.drain_filter(|x| *x % 2 == 0);
3370+
/// ```
33403371
#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")]
33413372
#[derive(Debug)]
33423373
pub struct DrainFilter<'a, T, F>

0 commit comments

Comments
 (0)