-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Extra methods for Option
#1597
Comments
Also, |
|
No, you might misunderstand what I want. pub fn give(&mut self, val: T) -> Option<T> {
::std::mem::replace(self, Some(val))
}
(assuming you're referencing libextra) Yes, we do use those a lot. They are a better and faster alternative to panicking, especially when making CLI tools. |
Wouldn't you get the same behaviour with abort on panic? Or is this a choice that varies inside a single project? The other cases are what i meant actually, are there lots of awkward matches when converting options to results? |
Nope, because of the way errors are handled and written to stderr. Abort on panic doesn't change that. |
For example, we don't want coreutils to do |
#1416 for previous discussion on |
Why not something like the new RefCell::replace method ? |
@Kerollmops Whereas, for |
But I do wonder |
I think the same kind of reflection can be applied to the So yes we can use What do you think ? |
Yes. It makes sense. |
These two methods have not the same behaviors:
EDIT: doesn't correctly read your answer, you are on my side, sorry. |
I noticed that a few potentially useful methods converting
Option
toResult
aren't currently implemented:ok_or_default
,err_or
,err_or_else
, anderr_or_default
.ok_or_default
could be useful as a complement tounwrap_or_default
when convertingOption
s toResult
s with a certain error type.All of the
err_or
functions are complements took_or
and aren't implemented at all.The text was updated successfully, but these errors were encountered: