summary refs log blame commit diff stats
path: root/src/graph.rs
blob: 47d652342fd3183fbe71e554f043c2bba2353da2 (plain) (tree)





























                                                                              
// Copyright (C) 2022 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::QueryError;

// TODO in the future, we may want to store &'pat IndexSet<String> either here
// or in the Pack.
#[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, QueryError> {
        let Self(inner) = self;
        match inner {
            None => Err(QueryError::Empty),
            Some(pack) => {
                let mut unpacker = Unpacker::new(pack, MAX_CALLS);
                De::deserialize(unpacker)
            },
        }
    }
}