mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-12 19:01:02 +00:00
@@ -529,7 +529,7 @@ macro_rules! array_impls {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<[T; $len], D::Error>
|
||||
where D: Deserializer,
|
||||
{
|
||||
deserializer.deserialize_seq($visitor::new())
|
||||
deserializer.deserialize_fixed_size_array($len, $visitor::new())
|
||||
}
|
||||
}
|
||||
)+
|
||||
|
||||
@@ -329,6 +329,19 @@ pub trait Deserializer {
|
||||
self.deserialize(visitor)
|
||||
}
|
||||
|
||||
/// This method hints that the `Deserialize` type is expecting a fixed size array. This allows
|
||||
/// deserializers to parse arrays that aren't tagged as arrays.
|
||||
///
|
||||
/// By default, this deserializes arrays from a sequence.
|
||||
#[inline]
|
||||
fn deserialize_fixed_size_array<V>(&mut self,
|
||||
_len: usize,
|
||||
visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: Visitor,
|
||||
{
|
||||
self.deserialize(visitor)
|
||||
}
|
||||
|
||||
/// This method hints that the `Deserialize` type is expecting a map of values. This allows
|
||||
/// deserializers to parse sequences that aren't tagged as maps.
|
||||
#[inline]
|
||||
|
||||
@@ -196,6 +196,8 @@ impl<T> Serialize for [T]
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
macro_rules! array_impls {
|
||||
($len:expr) => {
|
||||
impl<T> Serialize for [T; $len] where T: Serialize {
|
||||
@@ -203,7 +205,8 @@ macro_rules! array_impls {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
where S: Serializer,
|
||||
{
|
||||
serializer.serialize_seq(SeqIteratorVisitor::new(self.iter(), Some($len)))
|
||||
let visitor = SeqIteratorVisitor::new(self.iter(), Some($len));
|
||||
serializer.serialize_fixed_size_array(visitor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,6 +220,16 @@ pub trait Serializer {
|
||||
self.serialize_seq_elt(value)
|
||||
}
|
||||
|
||||
/// Serializes a fixed-size array.
|
||||
///
|
||||
/// By default this serializes an array as a sequence.
|
||||
#[inline]
|
||||
fn serialize_fixed_size_array<V>(&mut self, visitor: V) -> Result<(), Self::Error>
|
||||
where V: SeqVisitor,
|
||||
{
|
||||
self.serialize_seq(visitor)
|
||||
}
|
||||
|
||||
/// Serializes a tuple struct.
|
||||
///
|
||||
/// By default, tuple structs are serialized as a tuple.
|
||||
|
||||
Reference in New Issue
Block a user