dtolnay / serde-yaml

Strongly typed YAML library for Rust
Apache License 2.0
964 stars 164 forks source link

Disallow iterating Deserializers obtained from iteration #253

Closed dtolnay closed 2 years ago

dtolnay commented 2 years ago

The idiom for iterating over documents in a single input is:

let de = serde_yaml::Deserializer::from_str(…);
for document in de {
    let t = T::deserialize(document)?;
    …
}

It's confusing to assign semantics to the following however, since YAML only has one level of documents; documents cannot be nested inside of other documents.

let de = serde_yaml::Deserializer::from_str(…);
for document in de {
    for nested in document {
        let t = T::deserialize(nested)?;
    }
}

Previously this would do something confusing based on whether a T had been deserialized from document directly already or not. After this PR, document will always appear empty when iterated.