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

Migrate `next_*` methods to return `Option` #70

Closed
wants to merge 1 commit into from

Conversation

@frewsxcv
Copy link
Member

frewsxcv commented Mar 17, 2015

In the Rust standard library, the next method on the Iterator trait
returns an Option. Prior to this commit, the next and next_*
methods return Err<_, ()>. In an attempt to make some of the code more
idiomatic, I migrated these methods to return Option instead.

In the Rust standard library, the `next` method on the `Iterator` trait
returns an `Option`. Prior to this commit, the `next` and `next_*`
methods return `Err<_, ()>`. In an attempt to make some of the code more
idiomatic, I migrated these methods to return `Option` instead.
@SimonSapin
Copy link
Member

SimonSapin commented Mar 17, 2015

Thanks for the good intentions, but using Result<_, ()> instead of Option<_> was very deliberate. It enables using the try! macro, which I do extensively in Servo.

I’ve experimented with a generalized try! macro that works on Option as well as Result, but I’m not very happy with it since it doesn’t convert between them.

Until returning Option can be as ergonomic, I prefer sticking with Result.

@SimonSapin SimonSapin closed this Mar 17, 2015
@frewsxcv frewsxcv deleted the frewsxcv:next-opt branch Mar 17, 2015
@frewsxcv
Copy link
Member Author

frewsxcv commented Mar 17, 2015

since it doesn’t convert between them

What do you mean by this?

@SimonSapin
Copy link
Member

SimonSapin commented Mar 17, 2015

I mean that you can use this modified try! macro with an Option<T> expression in a context where the return type is Option<U>, or with a Result<T, E> expression where it is Result<U, E>, but not e.g. with a Option<T> expression where the return type is Result<U, E>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.