clippy: use strip_prefix instead of manual stripping
it's less error-prone (off-by-one!) Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
@ -996,8 +996,8 @@ pub fn get_fs_uuid(disk: &Disk) -> Result<String, Error> {
|
||||
let output = crate::tools::run_command(command, None)?;
|
||||
|
||||
for line in output.lines() {
|
||||
if line.starts_with("UUID=") {
|
||||
return Ok(line[5..].to_string());
|
||||
if let Some(uuid) = line.strip_prefix("UUID=") {
|
||||
return Ok(uuid.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,8 @@ pub struct ZFSPoolInfo {
|
||||
|
||||
|
||||
fn parse_optional_u64(i: &str) -> IResult<&str, Option<u64>> {
|
||||
if i.starts_with('-') {
|
||||
Ok((&i[1..], None))
|
||||
if let Some(rest) = i.strip_prefix('-') {
|
||||
Ok((rest, None))
|
||||
} else {
|
||||
let (i, value) = map_res(recognize(digit1), str::parse)(i)?;
|
||||
Ok((i, Some(value)))
|
||||
@ -40,8 +40,8 @@ fn parse_optional_u64(i: &str) -> IResult<&str, Option<u64>> {
|
||||
}
|
||||
|
||||
fn parse_optional_f64(i: &str) -> IResult<&str, Option<f64>> {
|
||||
if i.starts_with('-') {
|
||||
Ok((&i[1..], None))
|
||||
if let Some(rest) = i.strip_prefix('-') {
|
||||
Ok((rest, None))
|
||||
} else {
|
||||
let (i, value) = nom::number::complete::double(i)?;
|
||||
Ok((i, Some(value)))
|
||||
|
@ -151,10 +151,9 @@ fn parse_date_time_comp(max: usize) -> impl Fn(&str) -> IResult<&str, DateTimeVa
|
||||
return Ok((i, DateTimeValue::Range(value, end)))
|
||||
}
|
||||
|
||||
if i.starts_with("/") {
|
||||
let i = &i[1..];
|
||||
let (i, repeat) = parse_time_comp(max)(i)?;
|
||||
Ok((i, DateTimeValue::Repeated(value, repeat)))
|
||||
if let Some(time) = i.strip_prefix('/') {
|
||||
let (time, repeat) = parse_time_comp(max)(time)?;
|
||||
Ok((time, DateTimeValue::Repeated(value, repeat)))
|
||||
} else {
|
||||
Ok((i, DateTimeValue::Single(value)))
|
||||
}
|
||||
@ -163,15 +162,14 @@ fn parse_date_time_comp(max: usize) -> impl Fn(&str) -> IResult<&str, DateTimeVa
|
||||
|
||||
fn parse_date_time_comp_list(start: u32, max: usize) -> impl Fn(&str) -> IResult<&str, Vec<DateTimeValue>> {
|
||||
move |i: &str| {
|
||||
if i.starts_with("*") {
|
||||
let i = &i[1..];
|
||||
if i.starts_with("/") {
|
||||
let (n, repeat) = parse_time_comp(max)(&i[1..])?;
|
||||
if let Some(rest) = i.strip_prefix('*') {
|
||||
if let Some(time) = rest.strip_prefix('/') {
|
||||
let (n, repeat) = parse_time_comp(max)(time)?;
|
||||
if repeat > 0 {
|
||||
return Ok((n, vec![DateTimeValue::Repeated(start, repeat)]));
|
||||
}
|
||||
}
|
||||
return Ok((i, Vec::new()));
|
||||
return Ok((rest, Vec::new()));
|
||||
}
|
||||
|
||||
separated_nonempty_list(tag(","), parse_date_time_comp(max))(i)
|
||||
|
Reference in New Issue
Block a user