blob: 62ceed8d2cd661ad233dbd2691cfc02af434169f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
// Copyright (C) 2022, 2023 Soni L.
// SPDX-License-Identifier: MIT OR Apache-2.0
//! The results produced by a matched pattern.
use serde::de::Deserialize;
use crate::vm::MAX_CALLS;
use crate::vm::Pack;
use crate::vm::Unpacker;
use crate::errors::UnpackError;
// TODO in the future, we may want to store &'pat IndexSet<String> either here
// or in the Pack.
/// Match results. Produced by matching a `Pattern` against a `Deserializer`.
#[derive(Debug)]
pub struct Graph<'pat, 'de>(pub(crate) Option<Pack<'pat, 'de>>);
impl<'pat, 'de> Graph<'pat, 'de> {
/// Collect this graph into a given form.
pub fn collect<De: Deserialize<'de>>(self) -> Result<De, UnpackError> {
let Self(inner) = self;
match inner {
None => Err(UnpackError::Empty),
Some(pack) => {
let mut unpacker = Unpacker::new(pack, MAX_CALLS);
De::deserialize(unpacker)
},
}
}
}
|