From 9023a12ad41a1d166bba74c279bc7f3875abad73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Fri, 26 Apr 2019 14:59:35 +0200 Subject: [PATCH] feat: Introduce the unrankable error variant --- meilidb-data/src/serde/convert_to_number.rs | 30 ++++++++++----------- meilidb-data/src/serde/mod.rs | 4 +++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/meilidb-data/src/serde/convert_to_number.rs b/meilidb-data/src/serde/convert_to_number.rs index 57223a6c1..cf30e3b62 100644 --- a/meilidb-data/src/serde/convert_to_number.rs +++ b/meilidb-data/src/serde/convert_to_number.rs @@ -25,7 +25,7 @@ impl ser::Serializer for ConvertToNumber { } fn serialize_char(self, value: char) -> Result { - unimplemented!() + Err(SerializerError::UnrankableType { type_name: "char" }) } fn serialize_i8(self, value: i8) -> Result { @@ -73,25 +73,25 @@ impl ser::Serializer for ConvertToNumber { } fn serialize_bytes(self, _v: &[u8]) -> Result { - Err(SerializerError::UnserializableType { type_name: "&[u8]" }) + Err(SerializerError::UnrankableType { type_name: "&[u8]" }) } fn serialize_none(self) -> Result { - Err(SerializerError::UnserializableType { type_name: "Option" }) + Err(SerializerError::UnrankableType { type_name: "Option" }) } fn serialize_some(self, _value: &T) -> Result where T: Serialize, { - Err(SerializerError::UnserializableType { type_name: "Option" }) + Err(SerializerError::UnrankableType { type_name: "Option" }) } fn serialize_unit(self) -> Result { - Err(SerializerError::UnserializableType { type_name: "()" }) + Err(SerializerError::UnrankableType { type_name: "()" }) } fn serialize_unit_struct(self, _name: &'static str) -> Result { - Err(SerializerError::UnserializableType { type_name: "unit struct" }) + Err(SerializerError::UnrankableType { type_name: "unit struct" }) } fn serialize_unit_variant( @@ -101,7 +101,7 @@ impl ser::Serializer for ConvertToNumber { _variant: &'static str ) -> Result { - Err(SerializerError::UnserializableType { type_name: "unit variant" }) + Err(SerializerError::UnrankableType { type_name: "unit variant" }) } fn serialize_newtype_struct( @@ -123,15 +123,15 @@ impl ser::Serializer for ConvertToNumber { ) -> Result where T: Serialize, { - Err(SerializerError::UnserializableType { type_name: "newtype variant" }) + Err(SerializerError::UnrankableType { type_name: "newtype variant" }) } fn serialize_seq(self, _len: Option) -> Result { - Err(SerializerError::UnserializableType { type_name: "sequence" }) + Err(SerializerError::UnrankableType { type_name: "sequence" }) } fn serialize_tuple(self, _len: usize) -> Result { - Err(SerializerError::UnserializableType { type_name: "tuple" }) + Err(SerializerError::UnrankableType { type_name: "tuple" }) } fn serialize_tuple_struct( @@ -140,7 +140,7 @@ impl ser::Serializer for ConvertToNumber { _len: usize ) -> Result { - Err(SerializerError::UnserializableType { type_name: "tuple struct" }) + Err(SerializerError::UnrankableType { type_name: "tuple struct" }) } fn serialize_tuple_variant( @@ -151,11 +151,11 @@ impl ser::Serializer for ConvertToNumber { _len: usize ) -> Result { - Err(SerializerError::UnserializableType { type_name: "tuple variant" }) + Err(SerializerError::UnrankableType { type_name: "tuple variant" }) } fn serialize_map(self, _len: Option) -> Result { - Err(SerializerError::UnserializableType { type_name: "map" }) + Err(SerializerError::UnrankableType { type_name: "map" }) } fn serialize_struct( @@ -164,7 +164,7 @@ impl ser::Serializer for ConvertToNumber { _len: usize ) -> Result { - Err(SerializerError::UnserializableType { type_name: "struct" }) + Err(SerializerError::UnrankableType { type_name: "struct" }) } fn serialize_struct_variant( @@ -175,6 +175,6 @@ impl ser::Serializer for ConvertToNumber { _len: usize ) -> Result { - Err(SerializerError::UnserializableType { type_name: "struct variant" }) + Err(SerializerError::UnrankableType { type_name: "struct variant" }) } } diff --git a/meilidb-data/src/serde/mod.rs b/meilidb-data/src/serde/mod.rs index 75209c574..cf222c1bd 100644 --- a/meilidb-data/src/serde/mod.rs +++ b/meilidb-data/src/serde/mod.rs @@ -35,6 +35,7 @@ pub enum SerializerError { ParseNumberError(ParseNumberError), UnserializableType { type_name: &'static str }, UnindexableType { type_name: &'static str }, + UnrankableType { type_name: &'static str }, Custom(String), } @@ -61,6 +62,9 @@ impl fmt::Display for SerializerError { SerializerError::UnindexableType { type_name } => { write!(f, "{} are not an indexable type", type_name) }, + SerializerError::UnrankableType { type_name } => { + write!(f, "{} types can not be used for ranking", type_name) + }, SerializerError::Custom(s) => f.write_str(s), } }