Skip to content

Updated std::Option, std::Either and std::Result#8268

Closed
Kimundi wants to merge 1 commit intorust-lang:masterfrom
Kimundi:master
Closed

Updated std::Option, std::Either and std::Result#8268
Kimundi wants to merge 1 commit intorust-lang:masterfrom
Kimundi:master

Conversation

@Kimundi
Copy link
Contributor

@Kimundi Kimundi commented Aug 3, 2013

  • Lifted the quality of the either and result module to that of option
  • Made naming schemes consistent between Option, Result and Either

I also touched up on two issues that haven't yet reached a real consensus, so it wouldn't wonder me if this PR doesn't go through uncontested:

Todo:

Adding testcases for all function in the three modules. Even without the few functions I added, the coverage wasn't complete to begin with. But I'd rather do that as a follow up PR, I've touched to much code here already, need to go through them again with a clear mind.

Made naming schemes consistent between Option, Result and Either
Changed Options Add implementation to work like the maybe monad (return None if any of the inputs is None)
Renamed Option::unwrap to Option::get and Option::take_unwrap to Option::take_get
@bblum
Copy link
Contributor

bblum commented Aug 3, 2013

Not sure I agree with the renaming of unwrap -- I prefer get (and other operations with no suffix, like iter), to mean by-reference. At least there did not seem to be consensus, so deciding on one seems a little premature.

@lilyball
Copy link
Contributor

lilyball commented Aug 3, 2013

The naming RFC #7887 seems to suggest that get() returns a ref and that things like Option should continue to use the name unwrap() for consumption. So I'm a bit confused here.

@brson
Copy link
Contributor

brson commented Aug 3, 2013

I killed this build. Sorry. There have been some concerns raised here and on IRC, from reading the referenced bug it's not clear that a consensus was reached, and this is a very significant design decision.

@Kimundi
Copy link
Contributor Author

Kimundi commented Aug 6, 2013

With #8288 merged, this can be closed now.

@Kimundi Kimundi closed this Aug 6, 2013
bors added a commit that referenced this pull request Aug 7, 2013
According to #7887, we've decided to use the syntax of `fn map<U>(f: &fn(&T) -> U) -> U`, which passes a reference to the closure, and to `fn map_move<U>(f: &fn(T) -> U) -> U` which moves the value into the closure. This PR adds these `.map_move()` functions to `Option` and `Result`.

In addition, it has these other minor features:
 
* Replaces a couple uses of `option.get()`, `result.get()`, and `result.get_err()` with `option.unwrap()`, `result.unwrap()`, and `result.unwrap_err()`. (See #8268 and #8288 for a more thorough adaptation of this functionality.
* Removes `option.take_map()` and `option.take_map_default()`. These two functions can be easily written as `.take().map_move(...)`.
* Adds a better error message to `result.unwrap()` and `result.unwrap_err()`.
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jan 13, 2022
Fix `deref_addrof`

fixes rust-lang#8247

This would supersede rust-lang#8259

changelog: Don't lint `deref_addrof` when the dereference and the borrow occur in different contexts
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