spectec_ast_decode 1.0.0

Trait for decoding SpecTec AST S-expressions
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
impl<T: crate::Decode> crate::Decode for Vec<T> {
    fn decode<'a, I: Iterator<Item = &'a sexpr_parse::SExprItem>>(
        items: &mut std::iter::Peekable<I>,
    ) -> crate::Result<Self> {
        let mut parsed = Vec::new();
        while let Some(item) = items.peek() {
            if let Ok(out) = T::decode(&mut std::iter::once(*item).peekable()) {
                // We know that an item is available due to the success of the peek call
                #[allow(clippy::unwrap_used)]
                items.next().unwrap();
                parsed.push(out);
            } else {
                break;
            }
        }
        Ok(parsed)
    }
}