diff options
author | Narawit Rakket <narawitrakket@hotmail.com> | 2022-07-06 00:35:41 +0700 |
---|---|---|
committer | Abin Simon <abinsimon10@gmail.com> | 2022-07-09 17:27:32 +0530 |
commit | 201f6b2a22e716741941d9797ffedef724ed13c4 (patch) | |
tree | c69c69e36313c641fdf5a14428beac222da71f51 | |
parent | 73b14ab8c4cd3eb2fcd9f4e3d7a20551f4a36dae (diff) |
refactor: replace `if let` with `map_err`
-rw-r--r-- | src/color/theme.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/color/theme.rs b/src/color/theme.rs index e02d505..148753b 100644 --- a/src/color/theme.rs +++ b/src/color/theme.rs @@ -16,20 +16,19 @@ where struct ColorVisitor; impl<'de> serde::de::Visitor<'de> for ColorVisitor { type Value = Color; + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter.write_str( "`black`, `blue`, `dark_blue`, `cyan`, `dark_cyan`, `green`, `dark_green`, `grey`, `dark_grey`, `magenta`, `dark_magenta`, `red`, `dark_red`, `white`, `yellow`, `dark_yellow`, `u8`, or `3 u8 array`", ) } + fn visit_str<E>(self, value: &str) -> Result<Color, E> where E: serde::de::Error, { - if let Ok(c) = Color::try_from(value) { - Ok(c) - } else { - Err(E::invalid_value(serde::de::Unexpected::Str(value), &self)) - } + Color::try_from(value) + .map_err(|_| E::invalid_value(serde::de::Unexpected::Str(value), &self)) } fn visit_u64<E>(self, value: u64) -> Result<Color, E> |