diff options
author | hcpl <hcpl.prog@gmail.com> | 2018-10-28 12:36:40 +0200 |
---|---|---|
committer | hcpl <hcpl.prog@gmail.com> | 2018-10-28 12:36:40 +0200 |
commit | 93c0eaf24e33ab376ce9a5197ac759d37c3fcdf1 (patch) | |
tree | fa514155ffcc2b17919215e6a8a378371a952460 /src | |
parent | 3aec5a918a6cb39fa32e8a56725a3c2fc0ed6bc2 (diff) | |
download | milf-rs-93c0eaf24e33ab376ce9a5197ac759d37c3fcdf1.tar.gz milf-rs-93c0eaf24e33ab376ce9a5197ac759d37c3fcdf1.zip |
Support tuple Serde types for `Value`
Diffstat (limited to 'src')
-rw-r--r-- | src/value.rs | 63 |
1 files changed, 54 insertions, 9 deletions
diff --git a/src/value.rs b/src/value.rs index 64f4555..2e42dc3 100644 --- a/src/value.rs +++ b/src/value.rs @@ -675,9 +675,9 @@ impl ser::Serializer for Serializer { type Error = ::ser::Error; type SerializeSeq = SerializeVec; - type SerializeTuple = ser::Impossible<Value, ::ser::Error>; - type SerializeTupleStruct = ser::Impossible<Value, ::ser::Error>; - type SerializeTupleVariant = ser::Impossible<Value, ::ser::Error>; + type SerializeTuple = SerializeVec; + type SerializeTupleStruct = SerializeVec; + type SerializeTupleVariant = SerializeVec; type SerializeMap = SerializeMap; type SerializeStruct = SerializeMap; type SerializeStructVariant = ser::Impossible<Value, ::ser::Error>; @@ -800,23 +800,23 @@ impl ser::Serializer for Serializer { }) } - fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, ::ser::Error> { - Err(::ser::Error::UnsupportedType) + fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, ::ser::Error> { + self.serialize_seq(Some(len)) } - fn serialize_tuple_struct(self, _name: &'static str, _len: usize) + fn serialize_tuple_struct(self, _name: &'static str, len: usize) -> Result<Self::SerializeTupleStruct, ::ser::Error> { - Err(::ser::Error::UnsupportedType) + self.serialize_seq(Some(len)) } fn serialize_tuple_variant(self, _name: &'static str, _variant_index: u32, _variant: &'static str, - _len: usize) + len: usize) -> Result<Self::SerializeTupleVariant, ::ser::Error> { - Err(::ser::Error::UnsupportedType) + self.serialize_seq(Some(len)) } fn serialize_map(self, _len: Option<usize>) @@ -869,6 +869,51 @@ impl ser::SerializeSeq for SerializeVec { } } +impl ser::SerializeTuple for SerializeVec { + type Ok = Value; + type Error = ::ser::Error; + + fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), ::ser::Error> + where T: ser::Serialize + { + ser::SerializeSeq::serialize_element(self, value) + } + + fn end(self) -> Result<Value, ::ser::Error> { + ser::SerializeSeq::end(self) + } +} + +impl ser::SerializeTupleStruct for SerializeVec { + type Ok = Value; + type Error = ::ser::Error; + + fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), ::ser::Error> + where T: ser::Serialize + { + ser::SerializeSeq::serialize_element(self, value) + } + + fn end(self) -> Result<Value, ::ser::Error> { + ser::SerializeSeq::end(self) + } +} + +impl ser::SerializeTupleVariant for SerializeVec { + type Ok = Value; + type Error = ::ser::Error; + + fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), ::ser::Error> + where T: ser::Serialize + { + ser::SerializeSeq::serialize_element(self, value) + } + + fn end(self) -> Result<Value, ::ser::Error> { + ser::SerializeSeq::end(self) + } +} + impl ser::SerializeMap for SerializeMap { type Ok = Value; type Error = ::ser::Error; |