Skip to content

Commit

Permalink
Remove ok_or in favor of Option::ok_or
Browse files Browse the repository at this point in the history
Usages of `Option::ok_or` were removed because it was unstable at the time.
It is now stable of MSRV.
  • Loading branch information
AngelicosPhosphoros authored and Thomasdezeeuw committed Dec 17, 2023
1 parent 6042ec8 commit c5ddd6f
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,26 +474,17 @@ impl PartialOrd<LevelFilter> for Level {
}
}

fn ok_or<T, E>(t: Option<T>, e: E) -> Result<T, E> {
match t {
Some(t) => Ok(t),
None => Err(e),
}
}

impl FromStr for Level {
type Err = ParseLevelError;
fn from_str(level: &str) -> Result<Level, Self::Err> {
ok_or(
LOG_LEVEL_NAMES
.iter()
.position(|&name| name.eq_ignore_ascii_case(level))
.into_iter()
.filter(|&idx| idx != 0)
.map(|idx| Level::from_usize(idx).unwrap())
.next(),
ParseLevelError(()),
)
LOG_LEVEL_NAMES
.iter()
.position(|&name| name.eq_ignore_ascii_case(level))
.into_iter()
.filter(|&idx| idx != 0)
.map(|idx| Level::from_usize(idx).unwrap())
.next()
.ok_or(ParseLevelError(()))
}
}

Expand Down Expand Up @@ -595,13 +586,11 @@ impl PartialOrd<Level> for LevelFilter {
impl FromStr for LevelFilter {
type Err = ParseLevelError;
fn from_str(level: &str) -> Result<LevelFilter, Self::Err> {
ok_or(
LOG_LEVEL_NAMES
.iter()
.position(|&name| name.eq_ignore_ascii_case(level))
.map(|p| LevelFilter::from_usize(p).unwrap()),
ParseLevelError(()),
)
LOG_LEVEL_NAMES
.iter()
.position(|&name| name.eq_ignore_ascii_case(level))
.map(|p| LevelFilter::from_usize(p).unwrap())
.ok_or(ParseLevelError(()))
}
}

Expand Down

0 comments on commit c5ddd6f

Please sign in to comment.