Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework iterators to be distinct dynamic types for each iterator using protocols #671

Open
udoprog opened this issue Feb 29, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@udoprog
Copy link
Collaborator

udoprog commented Feb 29, 2024

Iterators currently suffer from complete type erasure. That is, every iterator is the same iterator type. There's also a lot of awkward plumbing it would be nice to get rid of which would allow iterators to be less special.

Current iterators are implemented by always wrapping them into one dynamic Iterator. Instead, iterators should be implemented by dynamic values implementing protocols. The Iterator type only needs to represent a dynamic iterator.

The first challenge is that we don't have "protocol hierarchies".

In Rust, an iterator implementation has to implement next, but all the other methods are optional. Rune doesn't support overriding optional methods like this, since it would require looking up two methods in order:

  • The implemented method.
  • If the method isn't implemented, fallback to the default implementation.

Hopefully this can be resolved efficiently when the RuntimeContext is constructed. Since each method must be an Arc, it should be simple enough to clone them so all possible methods can be filled out.

It would also be beneficial to introduce traits. Particularly when checking if a type implements a given trait or not.

A trait would simply be a collection of protocols, and a unique hash combination stored in a set to allow for testing whether a type implements a trait or not. The larger part would be implementing the necessary compiler and context infrastructure to define and implement traits.

@udoprog udoprog added the enhancement New feature or request label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant