mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-04 10:50:15 +00:00
Start using Option::is_none_or
This commit is contained in:
parent
26d2fbaef2
commit
41fa877362
3 changed files with 3 additions and 20 deletions
|
@ -304,22 +304,6 @@ pub fn slice_tails<T>(this: &[T]) -> impl Iterator<Item = &[T]> {
|
|||
(0..this.len()).map(|i| &this[i..])
|
||||
}
|
||||
|
||||
pub trait IsNoneOr {
|
||||
type Type;
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn is_none_or(self, s: impl FnOnce(Self::Type) -> bool) -> bool;
|
||||
}
|
||||
#[allow(unstable_name_collisions)]
|
||||
impl<T> IsNoneOr for Option<T> {
|
||||
type Type = T;
|
||||
fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool {
|
||||
match self {
|
||||
Some(v) => f(v),
|
||||
None => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue