1use super::Synced;
2
3use crate::runtime::task;
4
5use std::marker::PhantomData;
6
7pub(crate) struct Pop<'a, T: 'static> {
8 len: usize,
9 synced: &'a mut Synced,
10 _p: PhantomData<T>,
11}
12
13impl<'a, T: 'static> Pop<'a, T> {
14 pub(super) fn new(len: usize, synced: &'a mut Synced) -> Pop<'a, T> {
15 Pop {
16 len,
17 synced,
18 _p: PhantomData,
19 }
20 }
21}
22
23impl<'a, T: 'static> Iterator for Pop<'a, T> {
24 type Item = task::Notified<T>;
25
26 fn next(&mut self) -> Option<Self::Item> {
27 if self.len == 0 {
28 return None;
29 }
30
31 let ret = self.synced.pop();
32
33 // Should be `Some` when `len > 0`
34 debug_assert!(ret.is_some());
35
36 self.len -= 1;
37 ret
38 }
39
40 fn size_hint(&self) -> (usize, Option<usize>) {
41 (self.len, Some(self.len))
42 }
43}
44
45impl<'a, T: 'static> ExactSizeIterator for Pop<'a, T> {
46 fn len(&self) -> usize {
47 self.len
48 }
49}
50
51impl<'a, T: 'static> Drop for Pop<'a, T> {
52 fn drop(&mut self) {
53 for _ in self.by_ref() {}
54 }
55}
56