File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,31 @@ pub trait Fill<T> {
33
33
self . fill ( & mut iter) ;
34
34
iter
35
35
}
36
+
37
+ /// Fill the container and count the number of pulled items.
38
+ ///
39
+ /// The count should be equal to the number of items that have been inserted into the
40
+ /// container. At least a well-behaving containers inserts all items that are pulled from the
41
+ /// iterator.
42
+ ///
43
+ /// ## Examples
44
+ ///
45
+ /// For containers with a statically known capacity this can be an alternative to checking the
46
+ /// current state after a fill operation.
47
+ ///
48
+ /// ```
49
+ /// # use fill::Fill;
50
+ /// let mut option = None;
51
+ /// assert_eq!(option.fill_count(0..), 1);
52
+ /// assert_eq!(option.fill_count(1..), 0);
53
+ /// ```
54
+ fn fill_count < I > ( & mut self , iter : I ) -> usize
55
+ where I : IntoIterator < Item =T >
56
+ {
57
+ let mut count = 0 ;
58
+ self . fill ( iter. into_iter ( ) . inspect ( |_| count += 1 ) ) ;
59
+ count
60
+ }
36
61
}
37
62
38
63
#[ cfg( feature = "alloc" ) ]
You can’t perform that action at this time.
0 commit comments