Skip to content

std: Second pass stabilization of Result<T, E> #19961

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

Merged
merged 1 commit into from
Dec 21, 2014

Conversation

alexcrichton
Copy link
Member

This commit, like the second pass of Option, largely just stablizes the
existing functionality after renaming a few iterators.

The specific actions taken were:

  • The Ok and Err variants were marked #[stable] as the stability
    inheritance was since removed.
  • The as_mut method is now stable.
  • The map method is now stable
  • The map_err method is now stable
  • The iter, iter_mut, and into_iter methods now returned structures named
    after the method of iteration. The methods are also now all stable.
  • The and_then method is now stable.
  • The or_else method is now stable.
  • The unwrap family of functions are now all stable: unwrap_or,
    unwrap_or_else, unwrap, and unwrap_err.

There is a possible open extension to Result::{and, and_then} to make the
return type further generic over FromError (as proposed in #19078), but this
is a backwards compatible change due to the usage of default type parameters,
which makes the two functions safe to stabilize now regardless of the outcome of
that issue.

@alexcrichton
Copy link
Member Author

r? @aturon

@alexcrichton
Copy link
Member Author

cc @jakub-

pub struct Item<T> {
opt: Option<T>
}
/// An iterator over the a reference to the `Ok` value of a result.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads weird. Is that first 'a' needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Reworded slightly with a pushed update.

@tbu-
Copy link
Contributor

tbu- commented Dec 18, 2014

@alexcrichton This is only backwards-compatible if the code has specified the Result good enough, otherwise the inference could stop to work.

@alexcrichton
Copy link
Member Author

@tbu- can you elaborate? I'm not sure I understand what you mean sadly :(

@tbu-
Copy link
Contributor

tbu- commented Dec 18, 2014

The current signature of and in Result<T,E> is:

fn and<U>(self, res: Result<U, E>) -> Result<U, E>;

If this is changed to

fn and<U,F:FromError<E>>(self, res: Result<U, F>) -> Result<U,F>;

then the type of the parameter is less constrained. In particular one can see in the pull request you linked that additional type annotations were needed in the tests of this new and function.

@alexcrichton
Copy link
Member Author

Ah the PR actually recommended a signature like:

fn and<U,F:FromError<E>=E>(self, res: Result<U, F>) -> Result<U,F>;

which with the default type parameter I believe makes it a backwards-compatible change.

@reem
Copy link
Contributor

reem commented Dec 18, 2014

I actually do not think that it is wise to bake FromError into the basic operations surrounding Result, since it makes these ubiquitous ops only usable for errors, not for other uses of Result as a stop-gap for Either.

@tbu-
Copy link
Contributor

tbu- commented Dec 18, 2014

@alexcrichton Yeah, you're right, with the default type parameter this looks backwards-compatible.

bors added a commit that referenced this pull request Dec 19, 2014
std: Second pass stabilization of Result<T, E>

Reviewed-by: aturon
This commit, like the second pass of `Option`, largely just stablizes the
existing functionality after renaming a few iterators.

The specific actions taken were:

* The `Ok` and `Err` variants were marked `#[stable]` as the stability
  inheritance was since removed.
* The `as_mut` method is now stable.
* The `map` method is now stable
* The `map_err` method is now stable
* The `iter`, `iter_mut`, and `into_iter` methods now returned structures named
  after the method of iteration. The methods are also now all stable.
* The `and_then` method is now stable.
* The `or_else` method is now stable.
* The `unwrap` family of functions are now all stable: `unwrap_or`,
  `unwrap_or_else`, `unwrap`, and `unwrap_err`.

There is a possible open extension to `Result::{and, and_then}` to make the
return type further generic over `FromError` (as proposed in rust-lang#19078), but this
is a backwards compatible change due to the usage of default type parameters,
which makes the two functions safe to stabilize now regardless of the outcome of
that issue.
bors added a commit that referenced this pull request Dec 21, 2014
This commit, like the second pass of `Option`, largely just stablizes the
existing functionality after renaming a few iterators.

The specific actions taken were:

* The `Ok` and `Err` variants were marked `#[stable]` as the stability
  inheritance was since removed.
* The `as_mut` method is now stable.
* The `map` method is now stable
* The `map_err` method is now stable
* The `iter`, `iter_mut`, and `into_iter` methods now returned structures named
  after the method of iteration. The methods are also now all stable.
* The `and_then` method is now stable.
* The `or_else` method is now stable.
* The `unwrap` family of functions are now all stable: `unwrap_or`,
  `unwrap_or_else`, `unwrap`, and `unwrap_err`.

There is a possible open extension to `Result::{and, and_then}` to make the
return type further generic over `FromError` (as proposed in #19078), but this
is a backwards compatible change due to the usage of default type parameters,
which makes the two functions safe to stabilize now regardless of the outcome of
that issue.
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Dec 21, 2014
This commit, like the second pass of `Option`, largely just stablizes the
existing functionality after renaming a few iterators.

The specific actions taken were:

* The `Ok` and `Err` variants were marked `#[stable]` as the stability
  inheritance was since removed.
* The `as_mut` method is now stable.
* The `map` method is now stable
* The `map_err` method is now stable
* The `iter`, `iter_mut`, and `into_iter` methods now returned structures named
  after the method of iteration. The methods are also now all stable.
* The `and_then` method is now stable.
* The `or_else` method is now stable.
* The `unwrap` family of functions are now all stable: `unwrap_or`,
  `unwrap_or_else`, `unwrap`, and `unwrap_err`.

There is a possible open extension to `Result::{and, and_then}` to make the
return type further generic over `FromError` (as proposed in rust-lang#19078), but this
is a backwards compatible change due to the usage of default type parameters,
which makes the two functions safe to stabilize now regardless of the outcome of
that issue.
@bors bors merged commit a71686f into rust-lang:master Dec 21, 2014
@alexcrichton alexcrichton deleted the second-pass-result branch December 22, 2014 03:00
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.

6 participants