1use crate::alloc;
2use crate::compile::meta;
3
4use super::{FromValue, MaybeTypeOf, RuntimeError, Value, VmError};
5
6#[derive(Debug)]
8pub struct Iterator {
9 iter: Value,
10}
11
12impl Iterator {
13 pub(crate) fn new(iter: Value) -> Self {
14 Self { iter }
15 }
16
17 #[inline]
18 pub(crate) fn size_hint(&self) -> Result<(usize, Option<usize>), VmError> {
19 self.iter.protocol_size_hint()
20 }
21
22 #[inline]
23 pub(crate) fn next(&mut self) -> Result<Option<Value>, VmError> {
24 self.iter.protocol_next()
25 }
26}
27
28impl FromValue for Iterator {
29 #[inline]
30 fn from_value(value: Value) -> Result<Self, RuntimeError> {
31 value.into_iter().map_err(RuntimeError::from)
32 }
33}
34
35impl MaybeTypeOf for Iterator {
36 #[inline]
37 fn maybe_type_of() -> alloc::Result<meta::DocType> {
38 Ok(meta::DocType::empty())
39 }
40}