From 5693d84c79c5a460582f8c1563889970471eebf4 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sat, 8 Apr 2023 22:30:45 -0300 Subject: More clean up --- Cargo.toml | 2 +- src/errors.rs | 12 ++++++------ src/graph.rs | 7 ++++--- src/lib.rs | 1 + src/pattern.rs | 1 + src/vm/de/mod.rs | 1 - src/vm/de/unpacker.rs | 10 +++++----- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 748ae41..0feb58c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "datafu" -version = "0.1.0-alpha.1" +version = "0.1.0-alpha.2" authors = ["SoniEx2 "] license = "MIT OR Apache-2.0" description = "A Rust library for extracting data from config objects and other arbitrary object graphs." diff --git a/src/errors.rs b/src/errors.rs index ea1e60d..2c8b2e5 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -57,21 +57,21 @@ pub enum MatchError { Unsatisfiable, } +/// Error returned while unwrapping a `Graph`. #[derive(Debug)] #[non_exhaustive] -pub enum QueryError { +pub enum UnpackError { /// Returned if the deserialization recurses too deeply. StackOverflow, /// Returned if there's nothing to deserialize. Empty, - /// The query is unsatisfiable. This happens if e.g. there are multiple - /// values in the query but only one value can fit into the request. + /// The packed data is incompatible with the data structure. Unsatisfiable, /// Wrapped Serde error. Serde(serde::de::value::Error), } -impl std::fmt::Display for QueryError { +impl std::fmt::Display for UnpackError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::StackOverflow => write!(f, "stack overflow"), @@ -82,10 +82,10 @@ impl std::fmt::Display for QueryError { } } -impl std::error::Error for QueryError { +impl std::error::Error for UnpackError { } -impl serde::de::Error for QueryError { +impl serde::de::Error for UnpackError { fn custom(msg: T) -> Self where T: std::fmt::Display { Self::Serde(serde::de::value::Error::custom(msg)) } diff --git a/src/graph.rs b/src/graph.rs index 47d6523..c95cf34 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -8,19 +8,20 @@ use serde::de::Deserialize; use crate::vm::MAX_CALLS; use crate::vm::Pack; use crate::vm::Unpacker; -use crate::errors::QueryError; +use crate::errors::UnpackError; // TODO in the future, we may want to store &'pat IndexSet 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>); impl<'pat, 'de> Graph<'pat, 'de> { /// Collect this graph into a given form. - pub fn collect>(self) -> Result { + pub fn collect>(self) -> Result { let Self(inner) = self; match inner { - None => Err(QueryError::Empty), + None => Err(UnpackError::Empty), Some(pack) => { let mut unpacker = Unpacker::new(pack, MAX_CALLS); De::deserialize(unpacker) diff --git a/src/lib.rs b/src/lib.rs index 27d6c30..fa9f9e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,6 +116,7 @@ mod parser; mod pattern; mod vm; +pub use graph::Graph; pub use pattern::Pattern; pub use pattern::PatternBuilder; diff --git a/src/pattern.rs b/src/pattern.rs index 23d427e..a684cff 100644 --- a/src/pattern.rs +++ b/src/pattern.rs @@ -64,6 +64,7 @@ impl Pattern { } } +/// Builder for [`Pattern`]. pub struct PatternBuilder<'s, PKey=&'static str, OKey=&'static str, O=()> { input: &'s str, preds: Option>>, diff --git a/src/vm/de/mod.rs b/src/vm/de/mod.rs index 3cba18a..45274eb 100644 --- a/src/vm/de/mod.rs +++ b/src/vm/de/mod.rs @@ -23,7 +23,6 @@ use super::SerdeObject; use super::Type; use super::Value; use crate::errors::MatchError; -use crate::errors::QueryError; mod unpacker; diff --git a/src/vm/de/unpacker.rs b/src/vm/de/unpacker.rs index 8b16aa3..ce2e0d0 100644 --- a/src/vm/de/unpacker.rs +++ b/src/vm/de/unpacker.rs @@ -9,7 +9,7 @@ use std::collections::hash_map::IntoIter as HMIntoIter; use serde::de::IntoDeserializer; use serde::de::value::StrDeserializer; -use crate::errors::QueryError; +use crate::errors::UnpackError; use crate::vm::Pack; /// A `Deserializer` for Datafu output. @@ -54,7 +54,7 @@ impl<'pat, 'de> Unpacker<'pat, 'de> { } impl<'pat, 'de> serde::de::SeqAccess<'de> for Unpacker<'pat, 'de> { - type Error = QueryError; + type Error = UnpackError; fn next_element_seed>( &mut self, @@ -81,7 +81,7 @@ impl Drop for UnpackerFields<'_, '_, '_> { } impl<'pat, 'de> serde::de::MapAccess<'de> for UnpackerFields<'_, 'pat, 'de> { - type Error = QueryError; + type Error = UnpackError; fn next_key_seed>( &mut self, seed: T, @@ -108,7 +108,7 @@ impl<'pat, 'de> serde::de::MapAccess<'de> for UnpackerFields<'_, 'pat, 'de> { } impl<'pat, 'de> serde::Deserializer<'de> for &mut Unpacker<'pat, 'de> { - type Error = QueryError; + type Error = UnpackError; fn deserialize_any(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_bool(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_i8(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } @@ -192,7 +192,7 @@ impl<'pat, 'de> serde::Deserializer<'de> for &mut Unpacker<'pat, 'de> { } impl<'pat, 'de> serde::Deserializer<'de> for Unpacker<'pat, 'de> { - type Error = QueryError; + type Error = UnpackError; fn deserialize_any(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_bool(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_i8(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } -- cgit 1.4.1