Repository navigation
Tracking issue for Option::contains and Result::contains #62358
Copy link
Copy link
Closed
Labels
A-result-optionArea: Result and Option combinatorsArea: Result and Option combinatorsB-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.Libs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-closeThis PR / issue is in PFCP or FCP with a disposition to close it.This PR / issue is in PFCP or FCP with a disposition to close it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
This is a tracking issue for Option::contains and Result::contains.
The implementations are as follows:
pub fn contains(&self, x: &T) -> bool where T: PartialEq {
match self {
Some(y) => y == x,
None => false,
}
}
pub fn contains(&self, x: &T) -> bool where T: PartialEq {
match self {
Ok(y) => y == x,
Err(_) => false,
}
}
``Reacted by Moritz Kneilmann, Owen Troke-Billard, Rafa Couto, Mick Dekkers, Hudson Ayers, Stanislav Tkach, arielf212, Lucien Cartier-Tilet, Jari Pennanen, Jason Miller and 84 more
Reacted by Stepan Koltsov and Gwennan
Reacted by Ifiok Jr. and Brad Gibson
Reacted by Martin Indra
Metadata
Metadata
Assignees
Labels
A-result-optionArea: Result and Option combinatorsArea: Result and Option combinatorsB-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.Libs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-closeThis PR / issue is in PFCP or FCP with a disposition to close it.This PR / issue is in PFCP or FCP with a disposition to close it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Activity
Mark-Simulacrum commentedon Jul 4, 2019
Should we update the signatures to
fn contains<U>(&self, x: &U) -> bool where T: PartialEq<U>?Centril commentedon Jul 4, 2019
@Mark-Simulacrum That seems like a good idea -- type inference should be driven by
xin any case. Let's do that in the PR.timvermeulen commentedon Jul 4, 2019
Looks like
slice/Vec/VecDeque/LinkedListand possibly others have acontainsmethod that could benefit in the same way.soc commentedon Jul 4, 2019
@Mark-Simulacrum I didn't do that because I checked the collections first, and they were all invariant. Shall I change this for
OptionandResultonly?Mark-Simulacrum commentedon Jul 4, 2019
We usually can't change preexisting APIs due to inference breakage, but since this is new, we should be able to be general.
frewsxcv commentedon Jul 6, 2019
Are these functionally equivalent?
soc commentedon Jul 8, 2019
@frewsxcv Not quite, due to the requested variance changes.
czipperz commentedon Jul 14, 2019
What does that mean @soc?
soc commentedon Jul 14, 2019
@czipperz The implementation is:
The argument doesn't have to be of the same type as the value inside option/result, only that it knows how to compare itself to it. I. e. the operation is not invariant on the contained type, it allows an arbitrary type.
czipperz commentedon Jul 14, 2019
So there's no implementation of
PartialEq<Option<U>> for Option<T> where U: PartialEq<T>?timvermeulen commentedon Jul 14, 2019
There is indeed not, see #20063.
cells: add `contains` method to OptionalCell
150 remaining items
Auto merge of rust-lang#108095 - soc:drop-contains, r=Amanieu
soc commentedon Mar 29, 2023
@Centril methods have been removed, this issue can be closed now.
treewide: Remove option_result_contains feature
Auto merge of #108095 - soc:drop-contains, r=Amanieu
univerz commentedon Apr 19, 2023
i tried to remove
.contains(&y), but rewriting it to.as_ref().is_some_and(|x| x == &y)annoyed me so much i had to re/introduceContainstrait into mystdx.rsfilebjorn commentedon Apr 19, 2023
@univerz As per above commit one could also replace by
iter().any(...), but it is only a little bit shorter so not any less annoying. I'm sad about the outcome of this issue. :-(soc commentedon Apr 19, 2023
@univerz Perhaps option-ext can be of use to you!
Auto merge of #108095 - soc:drop-contains, r=Amanieu
Auto merge of #108095 - soc:drop-contains, r=Amanieu
Auto merge of #108095 - soc:drop-contains, r=Amanieu
Auto merge of #108095 - soc:drop-contains, r=Amanieu
cells: add `contains` method to OptionalCell
Merge tock#2964