diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2023-04-08 18:52:00 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2023-04-08 18:52:00 -0300 |
commit | d849f5e301fa47cfd87df1e7f1ad0346ddf387f1 (patch) | |
tree | a2480d05b753d94a6a8afee9832a902edf02d266 /src/graph.rs | |
parent | 6dd30531ac62f6a3a564b7341d43f6cd71b90794 (diff) |
Initial success
Diffstat (limited to 'src/graph.rs')
-rw-r--r-- | src/graph.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/graph.rs b/src/graph.rs new file mode 100644 index 0000000..47d6523 --- /dev/null +++ b/src/graph.rs @@ -0,0 +1,30 @@ +// 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) + }, + } + } +} |