mirror of
https://github.com/sharkdp/bat.git
synced 2025-08-15 10:49:56 +02:00
Reduce nesting in if blocks by short circuiting
This commit is contained in:
committed by
Martin Nordholts
parent
9124271eaf
commit
372e42f350
12
src/less.rs
12
src/less.rs
@ -11,13 +11,13 @@ pub fn retrieve_less_version(less_path: &dyn AsRef<OsStr>) -> Option<usize> {
|
||||
}
|
||||
|
||||
fn parse_less_version(output: &[u8]) -> Option<usize> {
|
||||
if output.starts_with(b"less ") {
|
||||
let version = std::str::from_utf8(&output[5..]).ok()?;
|
||||
let end = version.find(|c: char| !c.is_ascii_digit())?;
|
||||
version[..end].parse::<usize>().ok()
|
||||
} else {
|
||||
None
|
||||
if !output.starts_with(b"less ") {
|
||||
return None;
|
||||
}
|
||||
|
||||
let version = std::str::from_utf8(&output[5..]).ok()?;
|
||||
let end = version.find(|c: char| !c.is_ascii_digit())?;
|
||||
version[..end].parse::<usize>().ok()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Reference in New Issue
Block a user