You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes, Deserializers don't check to ensure that a SeqAccess or MapAccess was fully consumed during visitation (for instance, 3Hren/msgpack-rust#287). While those Deserializers should implement the proper checks (because there's no way to guarantee that the sequence was consumed), it would be nice if serde could help them out by having fixed-size collections call next_element anyway, to ensure that the collection is fully drained.
For example, the tuple implementation could be improved as follows:
fnvisit_seq<A>(self,mutseq:A) -> Result<Self::Value,A::Error>whereA:SeqAccess<'de>,{
$(
let $name = match try!(seq.next_element()){Some(value) => value,None => returnErr(Error::invalid_length($n,&self)),};)+
let mut excess: usize = 0;whileletSome(de::IgnoredAny) = try!(seq.next_element()){
excess += 1;}// Ensure there aren't too *many* elements in the sequencematch excess {0 => Ok(($($name,)+)),
n => Err(Error::invalid_length($len+n,&self)),}}
This proposal applies both to derived Deserializers (eg, for tuple structs) and to built-in standard library implementations (eg, for [T; N]).
Upon reflection, it's possible that this might be too damaging to non-self-describing formats. My expectation would be that such formats make use of the static parameters provided by the relevant deserialize methods, though (eg, use len in deserialize_tuple).
It actually occurred to me today that this behavior might be outright undesireable, as it would preclude certain useful compositions (for instance, flattening sequences into tuple structs, in addition to flattening maps into regular structs). Between that idea and the self-describing issue I'm going to retract this proposal.
Sometimes, Deserializers don't check to ensure that a
SeqAccess
orMapAccess
was fully consumed during visitation (for instance, 3Hren/msgpack-rust#287). While those Deserializers should implement the proper checks (because there's no way to guarantee that the sequence was consumed), it would be nice ifserde
could help them out by having fixed-size collections callnext_element
anyway, to ensure that the collection is fully drained.For example, the tuple implementation could be improved as follows:
This proposal applies both to derived Deserializers (eg, for tuple structs) and to built-in standard library implementations (eg, for
[T; N]
).Related to #1557
The text was updated successfully, but these errors were encountered: