diff --git a/src/firestore_serde/serializer.rs b/src/firestore_serde/serializer.rs index 2c22321..fd20841 100644 --- a/src/firestore_serde/serializer.rs +++ b/src/firestore_serde/serializer.rs @@ -233,7 +233,9 @@ impl serde::Serializer for FirestoreValueSerializer { ) } crate::firestore_serde::vector_serializers::FIRESTORE_VECTOR_TYPE_TAG_TYPE => { - crate::firestore_serde::vector_serializers::serialize_vector_for_firestore(value) + crate::firestore_serde::vector_serializers::serialize_vector_for_firestore( + self, value, + ) } _ => value.serialize(self), } diff --git a/src/firestore_serde/vector_serializers.rs b/src/firestore_serde/vector_serializers.rs index c86837c..b8319b1 100644 --- a/src/firestore_serde/vector_serializers.rs +++ b/src/firestore_serde/vector_serializers.rs @@ -1,8 +1,8 @@ -use crate::errors::{FirestoreError, FirestoreSerializationError}; -use crate::firestore_serde::serializer::SerializeVec; +use crate::errors::FirestoreError; +use crate::firestore_serde::serializer::FirestoreValueSerializer; use crate::FirestoreValue; use serde::de::{MapAccess, Visitor}; -use serde::{Deserializer, Serialize, Serializer}; +use serde::{Deserializer, Serialize}; pub(crate) const FIRESTORE_VECTOR_TYPE_TAG_TYPE: &str = "FirestoreVector"; @@ -25,270 +25,10 @@ where } pub fn serialize_vector_for_firestore( + firestore_value_serializer: FirestoreValueSerializer, value: &T, ) -> Result { - struct VectorSerializer; - - impl Serializer for VectorSerializer { - type Ok = FirestoreValue; - type Error = FirestoreError; - type SerializeSeq = crate::firestore_serde::serializer::SerializeVec; - type SerializeTuple = crate::firestore_serde::serializer::SerializeVec; - type SerializeTupleStruct = crate::firestore_serde::serializer::SerializeVec; - type SerializeTupleVariant = crate::firestore_serde::serializer::SerializeTupleVariant; - type SerializeMap = crate::firestore_serde::serializer::SerializeMap; - type SerializeStruct = crate::firestore_serde::serializer::SerializeMap; - type SerializeStructVariant = crate::firestore_serde::serializer::SerializeStructVariant; - - fn serialize_bool(self, _v: bool) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_i8(self, _v: i8) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_i16(self, _v: i16) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_i32(self, _v: i32) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_i64(self, _v: i64) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_u8(self, _v: u8) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_u16(self, _v: u16) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_u32(self, _v: u32) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_u64(self, _v: u64) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_f32(self, _v: f32) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_f64(self, _v: f64) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_char(self, _v: char) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_str(self, _v: &str) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_bytes(self, _v: &[u8]) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type", - ), - )) - } - - fn serialize_none(self) -> Result { - Ok(FirestoreValue::from( - gcloud_sdk::google::firestore::v1::Value { value_type: None }, - )) - } - - fn serialize_some(self, value: &T) -> Result - where - T: Serialize, - { - value.serialize(self) - } - - fn serialize_unit(self) -> Result { - Ok(FirestoreValue::from( - gcloud_sdk::google::firestore::v1::Value { value_type: None }, - )) - } - - fn serialize_unit_struct(self, _name: &'static str) -> Result { - self.serialize_unit() - } - - fn serialize_unit_variant( - self, - _name: &'static str, - _variant_index: u32, - variant: &'static str, - ) -> Result { - self.serialize_str(variant) - } - - fn serialize_newtype_struct( - self, - _name: &'static str, - value: &T, - ) -> Result - where - T: Serialize, - { - value.serialize(self) - } - - fn serialize_newtype_variant( - self, - _name: &'static str, - _variant_index: u32, - _variant: &'static str, - _value: &T, - ) -> Result - where - T: Serialize, - { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type: newtype_variant", - ), - )) - } - - fn serialize_seq(self, len: Option) -> Result { - Ok(SerializeVec { - none_as_null: false, - vec: Vec::with_capacity(len.unwrap_or(0)), - }) - } - - fn serialize_tuple(self, _len: usize) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type: tuple", - ), - )) - } - - fn serialize_tuple_struct( - self, - _name: &'static str, - _len: usize, - ) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type: tuple_struct", - ), - )) - } - - fn serialize_tuple_variant( - self, - _name: &'static str, - _variant_index: u32, - _variant: &'static str, - _len: usize, - ) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type: tuple_variant", - ), - )) - } - - fn serialize_map(self, _len: Option) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type: map", - ), - )) - } - - fn serialize_struct( - self, - _name: &'static str, - _len: usize, - ) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type: struct", - ), - )) - } - - fn serialize_struct_variant( - self, - _name: &'static str, - _variant_index: u32, - _variant: &'static str, - _len: usize, - ) -> Result { - Err(FirestoreError::SerializeError( - FirestoreSerializationError::from_message( - "Vector serializer doesn't support this type: struct_variant", - ), - )) - } - } - - let value_with_array = value.serialize(VectorSerializer {})?; + let value_with_array = value.serialize(firestore_value_serializer)?; Ok(FirestoreValue::from( gcloud_sdk::google::firestore::v1::Value {