From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/litemap/src/serde_helpers.rs | 168 ++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 third_party/rust/litemap/src/serde_helpers.rs (limited to 'third_party/rust/litemap/src/serde_helpers.rs') diff --git a/third_party/rust/litemap/src/serde_helpers.rs b/third_party/rust/litemap/src/serde_helpers.rs new file mode 100644 index 0000000000..b1ead938a0 --- /dev/null +++ b/third_party/rust/litemap/src/serde_helpers.rs @@ -0,0 +1,168 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +// @@@@@@@@@@@@@@@@ +// THIS FILE IS SHARED BETWEEN LITEMAP AND ZEROVEC. PLEASE KEEP IT IN SYNC FOR ALL EDITS +// @@@@@@@@@@@@@@@@ + +use serde::ser::{Impossible, Serialize, Serializer}; + +pub fn is_num_or_string(k: &T) -> bool { + // Serializer that errors in the same cases as serde_json::ser::MapKeySerializer + struct MapKeySerializerDryRun; + impl Serializer for MapKeySerializerDryRun { + type Ok = (); + // Singleton error type that implements serde::ser::Error + type Error = core::fmt::Error; + + type SerializeSeq = Impossible<(), Self::Error>; + type SerializeTuple = Impossible<(), Self::Error>; + type SerializeTupleStruct = Impossible<(), Self::Error>; + type SerializeTupleVariant = Impossible<(), Self::Error>; + type SerializeMap = Impossible<(), Self::Error>; + type SerializeStruct = Impossible<(), Self::Error>; + type SerializeStructVariant = Impossible<(), Self::Error>; + + fn serialize_str(self, _value: &str) -> Result { + Ok(()) + } + fn serialize_unit_variant( + self, + _name: &'static str, + _variant_index: u32, + _variant: &'static str, + ) -> Result { + Ok(()) + } + fn serialize_newtype_struct( + self, + _name: &'static str, + value: &T, + ) -> Result { + // Recurse + value.serialize(self) + } + fn serialize_bool(self, _value: bool) -> Result { + Err(core::fmt::Error) + } + fn serialize_i8(self, _value: i8) -> Result { + Ok(()) + } + fn serialize_i16(self, _value: i16) -> Result { + Ok(()) + } + fn serialize_i32(self, _value: i32) -> Result { + Ok(()) + } + fn serialize_i64(self, _value: i64) -> Result { + Ok(()) + } + serde::serde_if_integer128! { + fn serialize_i128(self, _value: i128) -> Result { + Ok(()) + } + } + fn serialize_u8(self, _value: u8) -> Result { + Ok(()) + } + fn serialize_u16(self, _value: u16) -> Result { + Ok(()) + } + fn serialize_u32(self, _value: u32) -> Result { + Ok(()) + } + fn serialize_u64(self, _value: u64) -> Result { + Ok(()) + } + serde::serde_if_integer128! { + fn serialize_u128(self, _value: u128) -> Result { + Ok(()) + } + } + fn serialize_f32(self, _value: f32) -> Result { + Err(core::fmt::Error) + } + fn serialize_f64(self, _value: f64) -> Result { + Err(core::fmt::Error) + } + fn serialize_char(self, _value: char) -> Result { + Ok(()) + } + fn serialize_bytes(self, _value: &[u8]) -> Result { + Err(core::fmt::Error) + } + fn serialize_unit(self) -> Result { + Err(core::fmt::Error) + } + fn serialize_unit_struct(self, _name: &'static str) -> Result { + Err(core::fmt::Error) + } + fn serialize_newtype_variant( + self, + _name: &'static str, + _variant_index: u32, + _variant: &'static str, + _value: &T, + ) -> Result { + Err(core::fmt::Error) + } + fn serialize_none(self) -> Result { + Err(core::fmt::Error) + } + fn serialize_some( + self, + _value: &T, + ) -> Result { + Err(core::fmt::Error) + } + fn serialize_seq(self, _len: Option) -> Result { + Err(core::fmt::Error) + } + fn serialize_tuple(self, _len: usize) -> Result { + Err(core::fmt::Error) + } + fn serialize_tuple_struct( + self, + _name: &'static str, + _len: usize, + ) -> Result { + Err(core::fmt::Error) + } + fn serialize_tuple_variant( + self, + _name: &'static str, + _variant_index: u32, + _variant: &'static str, + _len: usize, + ) -> Result { + Err(core::fmt::Error) + } + fn serialize_map(self, _len: Option) -> Result { + Err(core::fmt::Error) + } + fn serialize_struct( + self, + _name: &'static str, + _len: usize, + ) -> Result { + Err(core::fmt::Error) + } + fn serialize_struct_variant( + self, + _name: &'static str, + _variant_index: u32, + _variant: &'static str, + _len: usize, + ) -> Result { + Err(core::fmt::Error) + } + fn collect_str( + self, + _value: &T, + ) -> Result { + Ok(()) + } + } + k.serialize(MapKeySerializerDryRun).is_ok() +} -- cgit v1.2.3