Backport is_ok_and

On Rust versions that have it, this will be unused, so ignore the unused
import warning.
This commit is contained in:
Johannes Altmanninger 2023-12-06 11:02:07 +01:00
parent aa2f817b3b
commit d7a6c7f66a
5 changed files with 23 additions and 2 deletions

View file

@ -2,6 +2,7 @@ use std::pin::Pin;
use cxx::{CxxWString, UniquePtr};
#[allow(unused_imports)]
use crate::future::IsSomeAnd;
use crate::highlight::{HighlightSpec, HighlightSpecListFFI};
use crate::wchar::prelude::*;

View file

@ -21,8 +21,8 @@ use crate::env::environment::Environment;
use crate::env::EnvStack;
use crate::expand::INTERNAL_SEPARATOR;
use crate::fds::set_cloexec;
use crate::future::IsSomeAnd;
use crate::future::IsSorted;
#[allow(unused_imports)]
use crate::future::{IsOkAnd, IsSomeAnd, IsSorted};
use crate::global_safety::RelaxedAtomicBool;
use crate::highlight::{colorize, highlight_shell, HighlightRole, HighlightSpec};
use crate::operation_context::OperationContext;

View file

@ -24,6 +24,24 @@ impl<T> IsSomeAnd for Option<T> {
}
}
pub trait IsOkAnd {
type Type;
type Error;
#[allow(clippy::wrong_self_convention)]
fn is_ok_and(self, s: impl FnOnce(Self::Type) -> bool) -> bool;
}
impl<T, E> IsOkAnd for Result<T, E> {
type Type = T;
type Error = E;
fn is_ok_and(self, f: impl FnOnce(T) -> bool) -> bool {
match self {
Ok(v) => f(v),
Err(_) => false,
}
}
}
pub trait IsSorted {
type T;
fn is_sorted_by(&self, pred: impl Fn(&Self::T, &Self::T) -> Option<std::cmp::Ordering>)

View file

@ -11,6 +11,7 @@ use crate::compat::MB_CUR_MAX;
use crate::complete::{Completion, CompletionListFfi};
use crate::editable_line::EditableLine;
use crate::fallback::{fish_wcswidth, fish_wcwidth};
#[allow(unused_imports)]
use crate::future::IsSomeAnd;
use crate::highlight::{highlight_shell, HighlightRole, HighlightSpec};
use crate::operation_context::OperationContext;

View file

@ -27,6 +27,7 @@ use crate::curses::{term, tparm0, tparm1};
use crate::env::{EnvStackRef, Environment, TERM_HAS_XN};
use crate::fallback::fish_wcwidth;
use crate::flog::FLOGF;
#[allow(unused_imports)]
use crate::future::IsSomeAnd;
use crate::global_safety::RelaxedAtomicBool;
use crate::highlight::{HighlightColorResolver, HighlightSpecListFFI};