You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are two things here. Iterators and Iterables. Iterables are the equivalent of IntoIterator, which themselves store no iteration state but can be "iterated over", producing a temporary iterator type. Iterators are the equivalent of Iterator which store iterator state and can get "exhausted" once iterated.
Most language with iteration glue have that glue prioritize iterables, not iterators, though usually there's a standard way to make iterators be iterables as well. For example, in Javascript, iterables have an @@iterator method that produces an iterator, and anything with a next() method that returns an object with done: bool and value fields. The way you make an iterator also an iterable is just to give it a [Symbol.iterator]() {return this;} method.
From an ICU4X standpoint it's more important for us to prioritize iterators; most of the time we have methods that take additional parameters to produce an iterator, so they're not themselves iterable.
An actual next() method is not generated (in the long run we can make htis configurable). This would generate an ICU4XLineBreakIterator struct with a properly wrapped next() class that produces the {done, value} enum and additionally has a return this@@iterator method.
We might want to add a supports=iterators name/value Diplomat attribute CFG as well.
For iterables, we can also add a #[diplomat::attr(*, iterable)] type that can be tagged on a single method that has no additional parameters to mark things.
Split out from #251
There are two things here. Iterators and Iterables. Iterables are the equivalent of
IntoIterator
, which themselves store no iteration state but can be "iterated over", producing a temporary iterator type. Iterators are the equivalent ofIterator
which store iterator state and can get "exhausted" once iterated.Most language with iteration glue have that glue prioritize iterables, not iterators, though usually there's a standard way to make iterators be iterables as well. For example, in Javascript, iterables have an
@@iterator
method that produces an iterator, and anything with anext()
method that returns an object withdone: bool
andvalue
fields. The way you make an iterator also an iterable is just to give it a[Symbol.iterator]() {return this;}
method.From an ICU4X standpoint it's more important for us to prioritize iterators; most of the time we have methods that take additional parameters to produce an iterator, so they're not themselves iterable.
Roughly, we should do something like this:
An actual
next()
method is not generated (in the long run we can make htis configurable). This would generate anICU4XLineBreakIterator
struct with a properly wrappednext()
class that produces the{done, value}
enum and additionally has areturn this
@@iterator
method.We might want to add a
supports=iterators
name/value Diplomat attribute CFG as well.For iterables, we can also add a
#[diplomat::attr(*, iterable)]
type that can be tagged on a single method that has no additional parameters to mark things.Originally posted by @Manishearth in #251 (comment)
The text was updated successfully, but these errors were encountered: