summaryrefslogtreecommitdiffstats
path: root/crates/core/c8y_smartrest/src
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-02-07 09:47:54 +0100
committerMatthias Beyer <matthias.beyer@ifm.com>2022-02-11 08:40:23 +0100
commit2e8dbee1be73558b2cfb80cefede93f17f8321ce (patch)
tree897161a5b40bc3f659f7daf08e201af62a1f32a2 /crates/core/c8y_smartrest/src
parent0f074d549de9d6c9f147d4e16cac294c34db06b8 (diff)
Replace match with function chaining
This fixes clippy lint `clippy::try_err` by replacing the match block with function chaining and thus reduces boilerplate in the good-case where no conversion happens. Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
Diffstat (limited to 'crates/core/c8y_smartrest/src')
-rw-r--r--crates/core/c8y_smartrest/src/smartrest_deserializer.rs19
1 files changed, 9 insertions, 10 deletions
diff --git a/crates/core/c8y_smartrest/src/smartrest_deserializer.rs b/crates/core/c8y_smartrest/src/smartrest_deserializer.rs
index 52be56b9..b634b07d 100644
--- a/crates/core/c8y_smartrest/src/smartrest_deserializer.rs
+++ b/crates/core/c8y_smartrest/src/smartrest_deserializer.rs
@@ -223,11 +223,11 @@ impl SmartRestLogRequest {
.flexible(true)
.from_reader(smartrest.as_bytes());
- match rdr.deserialize().next() {
- Some(Ok(record)) => Ok(record),
- Some(Err(err)) => Err(err)?,
- None => panic!("empty request"),
- }
+ rdr.deserialize()
+ .next()
+ .ok_or_else(|| panic!("empty request"))
+ .unwrap() // does already panic before this, so this unwrap is only required for type lineup
+ .map_err(SmartRestDeserializerError::from)
}
}
@@ -244,11 +244,10 @@ impl SmartRestRestartRequest {
.flexible(true)
.from_reader(smartrest.as_bytes());
- match rdr.deserialize().next() {
- Some(Ok(record)) => Ok(record),
- Some(Err(err)) => Err(err)?,
- None => Err(SmartRestDeserializerError::EmptyRequest),
- }
+ rdr.deserialize()
+ .next()
+ .ok_or(SmartRestDeserializerError::EmptyRequest)?
+ .map_err(SmartRestDeserializerError::from)
}
}