1use crate::{vtable::HasDropVt, IDeterminantProvider, IPtrMut, IPtrOwned};
2
3#[crate::stabby]
5pub trait Iterator {
6 type Item: IDeterminantProvider<()>;
8 extern "C" fn next(&mut self) -> crate::Option<Self::Item>;
10 extern "C" fn size_hint(&self) -> crate::Tuple<usize, crate::Option<usize>>;
12}
13
14impl<T: core::iter::Iterator> Iterator for T
15where
16 T::Item: IDeterminantProvider<()>,
17{
18 type Item = T::Item;
19 extern "C" fn next(&mut self) -> crate::Option<Self::Item> {
20 core::iter::Iterator::next(self).into()
21 }
22 extern "C" fn size_hint(&self) -> crate::Tuple<usize, crate::Option<usize>> {
23 let (min, max) = core::iter::Iterator::size_hint(self);
24 crate::Tuple(min, max.into())
25 }
26}
27
28impl<Vt: HasDropVt, P: IPtrOwned + IPtrMut, Output: IDeterminantProvider<()>> core::iter::Iterator
29 for crate::Dyn<'_, P, crate::vtable::VTable<StabbyVtableIterator<'_, Output>, Vt>>
30{
31 type Item = Output;
32 fn next(&mut self) -> Option<Self::Item> {
33 unsafe {
35 (self.vtable().head.next.as_ref_unchecked())(
36 self.ptr_mut().as_mut(),
37 core::marker::PhantomData,
38 )
39 .into()
40 }
41 }
42 fn size_hint(&self) -> (usize, Option<usize>) {
43 let crate::Tuple(min, max) = unsafe { (self.vtable().head.size_hint.as_ref_unchecked())(self.ptr().as_ref(), core::marker::PhantomData) };
45 (min, max.into())
46 }
47}
48
49impl<'a, Output> crate::vtable::CompoundVt<'a> for dyn core::iter::Iterator<Item = Output>
50where
51 dyn Iterator<Item = Output>: crate::vtable::CompoundVt<'a>,
52{
53 type Vt<T> = <dyn Iterator<Item = Output> as crate::vtable::CompoundVt<'a>>::Vt<T>;
54}