Skip to content

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