Function rocket::mtls::oid::asn1_rs::nom::lib::std::iter::repeat_n

source ·
pub fn repeat_n<T>(element: T, count: usize) -> RepeatN<T> 
where T: Clone,
🔬This is a nightly-only experimental API. (iter_repeat_n)
Available on crate feature mtls only.
Expand description

Creates a new iterator that repeats a single element a given number of times.

The repeat_n() function repeats a single value exactly n times.

This is very similar to using repeat() with Iterator::take(), but there are two differences:

  • repeat_n() can return the original value, rather than always cloning.
  • repeat_n() produces an ExactSizeIterator.


Basic usage:

use std::iter;

// four of the number four:
let mut four_fours = iter::repeat_n(4, 4);


// no more fours

For non-Copy types,

use std::iter;

let v: Vec<i32> = Vec::with_capacity(123);
let mut it = iter::repeat_n(v, 5);

for i in 0..4 {
    // It starts by cloning things
    let cloned =;
    assert_eq!(cloned.len(), 0);
    assert_eq!(cloned.capacity(), 0);

// ... but the last item is the original one
let last =;
assert_eq!(last.len(), 0);
assert_eq!(last.capacity(), 123);

// ... and now we're done