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:
Fabian Grünbichler 2021-01-18 13:50:28 +01:00
parent 28f3b0df9e
commit 724e2f47f9

View File

@ -127,13 +127,13 @@ pub async fn send_command<P>(
if rx.read_line(&mut data).await? == 0 { if rx.read_line(&mut data).await? == 0 {
bail!("no response"); bail!("no response");
} }
if data.starts_with("OK: ") { if let Some(res) = data.strip_prefix("OK: ") {
match data[4..].parse::<Value>() { match res.parse::<Value>() {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(err) => bail!("unable to parse json response - {}", err), Err(err) => bail!("unable to parse json response - {}", err),
} }
} else if data.starts_with("ERROR: ") { } else if let Some(err) = data.strip_prefix("ERROR: ") {
bail!("{}", &data[7..]); bail!("{}", err);
} else { } else {
bail!("unable to parse response: {}", data); bail!("unable to parse response: {}", data);
} }