From 336941c342f83259f987696649b20edf665683bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Thu, 16 Nov 2023 16:07:46 +0100 Subject: [PATCH] Use constants in match statement --- src/consts.rs | 1 + src/de.rs | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/consts.rs b/src/consts.rs index f24bfeb7..b2abb06e 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -7,6 +7,7 @@ pub const MAJOR_STR: u8 = 3; pub const MAJOR_ARRAY: u8 = 4; pub const MAJOR_MAP: u8 = 5; pub const MAJOR_SIMPLE: u8 = 7; +pub const MAJOR_FLOAT: u8 = 7; pub const SIMPLE_FALSE: u8 = 20; pub const SIMPLE_TRUE: u8 = 21; diff --git a/src/de.rs b/src/de.rs index 4f9d60c4..92533e1f 100644 --- a/src/de.rs +++ b/src/de.rs @@ -262,18 +262,17 @@ impl<'de> Deserializer<'de> { } fn ignore(&mut self) -> Result<()> { - match self.peek_major()? { - 0 => self.ignore_int(0)?, - 1 => self.ignore_int(1)?, - 2 => self.ignore_bytes(2)?, - 3 => self.ignore_bytes(3)?, - 4 => self.ignore_array(4, 1)?, - 5 => self.ignore_array(5, 2)?, + let major = self.peek_major()?; + match major { + MAJOR_POSINT | MAJOR_NEGINT => self.ignore_int(major)?, + MAJOR_BYTES | MAJOR_STR => self.ignore_bytes(major)?, + MAJOR_ARRAY => self.ignore_array(MAJOR_ARRAY, 1)?, + MAJOR_MAP => self.ignore_array(MAJOR_MAP, 2)?, 6 => { self.ignore_int(6)?; self.ignore()?; } - 7 => self.ignore_float()?, + MAJOR_FLOAT => self.ignore_float()?, _ => return Err(Error::DeserializeBadMajor), } Ok(())