~tdeo/serde_bare

51e8c763b4b3a8c05a34ea31757fda951f802d1c — Tadeo Kondrak 11 months ago 65fd51b
Clarify some allowed behaviour to allow varint deserialization

Since custom functions can't be used in Deserialize implementations,
we have to use some existing functions in special ways.
1 files changed, 12 insertions(+), 4 deletions(-)

M src/de.rs
M src/de.rs => src/de.rs +12 -4
@@ 298,6 298,7 @@ where
    }

    /// BARE type: \[len\]T
    /// Deserializing fewer elements than `len` is allowed.
    fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: de::Visitor<'de>,


@@ 325,16 326,18 @@ where
    }

    /// BARE type: struct
    /// `name` is ignored.
    /// Deserializing fewer elements than `len` is allowed.
    fn deserialize_tuple_struct<V>(
        self,
        _name: &'static str,
        _len: usize,
        len: usize,
        visitor: V,
    ) -> Result<V::Value, Self::Error>
    where
        V: de::Visitor<'de>,
    {
        struct Seq<'a, R>(&'a mut Deserializer<R>);
        struct Seq<'a, R>(&'a mut Deserializer<R>, usize);
        impl<'de, 'a, R> de::SeqAccess<'de> for Seq<'a, R>
        where
            R: Read,


@@ 345,10 348,15 @@ where
            where
                T: de::DeserializeSeed<'de>,
            {
                Ok(Some(seed.deserialize(&mut *self.0)?))
                if self.1 == 0 {
                    Ok(None)
                } else {
                    self.1 -= 1;
                    Ok(Some(seed.deserialize(&mut *self.0)?))
                }
            }
        }
        visitor.visit_seq(Seq::<'a, R>(self))
        visitor.visit_seq(Seq::<'a, R>(self, len))
    }

    /// BARE type: map\[T\]U