Closed
Description
Today I got myself in a situation in which I had two Option<T>
values, and I wanted to return the only one that was Some
. If both of them were Some
, then I'd rather return None
. I think it would be perfect to have a xor
method, very similar to the or
method:
impl<T> Option<T> {
//...
fn xor(self, optb: Option<T>) -> Option<T> {
match (&self, &optb) {
(&Some(_), &None) => self,
(&None, &Some(_)) => optb,
_ => None,
}
}
}
I think that would solve my problem nicely, and could be useful for a lot of people as well.
Metadata
Metadata
Assignees
Labels
Blocker: Implemented in the nightly compiler and unstable.Category: An issue tracking the progress of sth. like the implementation of an RFCCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Relevant to the library API team, which will review and decide on the PR/issue.This issue / PR is in PFCP or FCP with a disposition to merge it.The final comment period is finished for this PR / Issue.