Skip to content

Migrate next_* methods to return Option #70

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

Closed
wants to merge 1 commit into from

Conversation

frewsxcv
Copy link
Contributor

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

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 next-opt branch March 17, 2015 01:02
@frewsxcv
Copy link
Contributor Author

since it doesn’t convert between them

What do you mean by this?

@SimonSapin
Copy link
Member

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants