1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use ControlFlow;
use crate;
/// A collector that [`drops`](drop) every collected items.
///
/// # Examples
///
/// ```no_run
/// use better_collect::{prelude::*, mem::Dropping};
/// use std::cell::Cell;
///
/// #[derive(Clone)]
/// struct IncCountOnDrop<'a>(&'a Cell<i32>);
///
/// impl Drop for IncCountOnDrop<'_> {
/// fn drop(&mut self) {
/// self.0.update(|count| count + 1);
/// }
/// }
///
/// let count = Cell::new(0);
///
/// std::iter::repeat_n(IncCountOnDrop(&count), 100)
/// .feed_into(Dropping);
///
/// assert_eq!(count.get(), 100);
/// ```
;
// #[cfg(all(test, feature = "std"))]
// mod proptests {
// use std::{borrow::Borrow, cell::Cell, rc::Rc};
// use proptest::prelude::*;
// use proptest::test_runner::TestCaseResult;
// use crate::test_utils::{BasicCollectorTester, CollectorTesterExt, PredError};
// use super::*;
// proptest! {
// #[test]
// fn all_collect_methods(
// count in ..5_usize,
// ) {
// all_collect_methods_impl(count)?;
// }
// }
// fn all_collect_methods_impl(count: usize) -> TestCaseResult {
// let actual_count = Rc::new(Cell::new(0_usize));
// #[derive(Clone)]
// struct IncCountOnDrop<T: Borrow<Cell<usize>>>(T);
// impl<T: Borrow<Cell<usize>>> Drop for IncCountOnDrop<T> {
// fn drop(&mut self) {
// self.0.borrow().update(|count| count + 1);
// }
// }
// BasicCollectorTester {
// iter_factory: || std::iter::repeat_with(move || IncCountOnDrop(actual_count)).take(count),
// collector_factory: || Dropping,
// should_break_pred: |_| false,
// pred: |_, _, remaining| {
// if actual_count.get() != count {
// Err(PredError::IncorrectOutput)
// } else if remaining.count() > 0 {
// Err(PredError::IncorrectIterConsumption)
// } else {
// Ok(())
// }
// },
// }
// .test_collector()
// }
// }