Skip to content

Commit

Permalink
Merge #935
Browse files Browse the repository at this point in the history
935: Convert delegate doctest to unit tests r=cuviper a=cuviper

The documented example wasn't functional, and this broke on nightly since rust-lang/rust#96630.

We can't actually doctest a nonexported macro, but a unit test will do.

Co-authored-by: Josh Stone <cuviper@gmail.com>
  • Loading branch information
bors[bot] and cuviper committed May 12, 2022
2 parents 9dc52d7 + 36bd58a commit a866566
Showing 1 changed file with 48 additions and 9 deletions.
57 changes: 48 additions & 9 deletions src/delegate.rs
Expand Up @@ -8,15 +8,6 @@
/// declared with an `inner` field.
///
/// The implementation of `IntoParallelIterator` should be added separately.
///
/// # Example
///
/// ```
/// delegate_iterator!{
/// MyIntoIter<T, U> => (T, U),
/// impl<T: Ord + Send, U: Send>
/// }
/// ```
macro_rules! delegate_iterator {
($iter:ty => $item:ty ,
impl $( $args:tt )*
Expand Down Expand Up @@ -68,3 +59,51 @@ macro_rules! delegate_indexed_iterator {
}
}
}

#[test]
fn unindexed_example() {
use crate::collections::btree_map::IntoIter;
use crate::iter::plumbing::*;
use crate::prelude::*;

use std::collections::BTreeMap;

struct MyIntoIter<T: Ord + Send, U: Send> {
inner: IntoIter<T, U>,
}

delegate_iterator! {
MyIntoIter<T, U> => (T, U),
impl<T: Ord + Send, U: Send>
}

let map = BTreeMap::from([(1, 'a'), (2, 'b'), (3, 'c')]);
let iter = MyIntoIter {
inner: map.into_par_iter(),
};
let vec: Vec<_> = iter.map(|(k, _)| k).collect();
assert_eq!(vec, &[1, 2, 3]);
}

#[test]
fn indexed_example() {
use crate::iter::plumbing::*;
use crate::prelude::*;
use crate::vec::IntoIter;

struct MyIntoIter<T: Send> {
inner: IntoIter<T>,
}

delegate_indexed_iterator! {
MyIntoIter<T> => T,
impl<T: Send>
}

let iter = MyIntoIter {
inner: vec![1, 2, 3].into_par_iter(),
};
let mut vec = vec![];
iter.collect_into_vec(&mut vec);
assert_eq!(vec, &[1, 2, 3]);
}

0 comments on commit a866566

Please sign in to comment.