Skip to content

Commit

Permalink
format-parser: Add is_some_and method for Option<T>
Browse files Browse the repository at this point in the history
Workaround for Ubuntu 18.04, since we still use it for the GCC 4.8 CI.
The default Rust package is 1.65 (and unlikely to change I assume?),
but the generic format parser library uses `is_some_and` which was
introduced in 1.70. So this is a simple reimplementation, directly taken
from the standard library sources.

libgrust/ChangeLog:

	* libformat_parser/generic_format_parser/src/lib.rs: Add IsSomeAnd<T>
	trait, impl it for Option<T>.
  • Loading branch information
CohenArthur committed Feb 26, 2024
1 parent 3cd6cd7 commit a32eeae
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libgrust/libformat_parser/generic_format_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ fn is_id_continue(c: char) -> bool {
unicode_xid::UnicodeXID::is_xid_continue(c)
}

// Workaround for Ubuntu 18.04. The default Rust package is 1.65 (and unlikely to change I assume?), but the
// generic format parser library uses `is_some_and` which was introduced in 1.70. So this is a reimplementation,
// directly taken from the standard library sources
trait IsSomeAnd<T> {
fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool;
}

impl<T> IsSomeAnd<T> for Option<T> {
fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool {
match self {
None => false,
Some(x) => f(x),
}
}
}

// use rustc_lexer::unescape;
pub use Alignment::*;
pub use Count::*;
Expand Down

0 comments on commit a32eeae

Please sign in to comment.