pub(crate) struct SeqDeserializer<'a, T: std::io::BufRead + std::io::Seek> {
pub root: &'a mut crate::Deserializer<T>,
}
impl<'d, 'a, T: std::io::BufRead + std::io::Seek> serde::de::SeqAccess<'d> for SeqDeserializer<'a, T> {
type Error = crate::DeserializeError;
fn next_element_seed<K: serde::de::DeserializeSeed<'d>>(&mut self, seed: K) -> Result<Option<K::Value>, crate::DeserializeError> {
match self.root.read_line(true)? {
crate::ReadResult::Inline => {
return Err(crate::DeserializeErrorKind::Invalid(
format!("Inline string not allowed for list"))
.at(self.root.location))
}
crate::ReadResult::None => {
return Ok(None)
}
crate::ReadResult::Multiline => {
}
}
if self.root.peek_byte()? == Some(b':') {
self.root.input.consume(1);
self.root.location.add_columns(1);
self.root.buf.clear();
self.root.input.read_until(b'\n', &mut self.root.buf)?;
let s = crate::from_utf8(&self.root.buf, self.root.location)?;
if let Some(i) = s.find(|c: char| !c.is_whitespace()) {
if s.as_bytes()[i] != b'#' {
return Err(crate::DeserializeErrorKind::Invalid(
format!("Expected newline after `:` found {:?}", s))
.at(self.root.location))
}
}
self.root.location.add_lines(1);
self.root.position = crate::Position::Newline;
let r = seed.deserialize(&mut *self.root);
r.map(Some)
} else {
self.root.buf.clear();
let read = self.root.input.read_until(b'\n', &mut self.root.buf)?;
if let Some('#') = bstr::ByteSlice::chars(&self.root.buf[..]).find(|c| !c.is_whitespace()) {
self.root.location.add_lines(1);
return self.next_element_seed(seed)
}
self.root.seek_backwards(read)?;
self.root.position = crate::Position::Inline;
seed.deserialize(&mut *self.root).map(Some)
}
}
}