Skip to content

Commit

Permalink
Rename ValueConversionType to ExpectedConstantTy
Browse files Browse the repository at this point in the history
- Modify QueryArg/QueryArgs to use ExpectedConstantTy
- Removed ConstantTy::Unknown
  • Loading branch information
bluk committed Sep 7, 2023
1 parent 22394d5 commit 2b6d23b
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 104 deletions.
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use alloc::vec::Vec;
use core::iter;
#[cfg(feature = "std")]
use std::vec::Vec;
use utils::{TryFromConstantArray, ValueConversionTy, VoidResult};
use utils::{ExpectedConstantTy, TryFromConstantArray, VoidResult};

use either::Either;
use generic_array::{functional::FunctionalSequence, ArrayLength, GenericArray};
Expand Down Expand Up @@ -343,9 +343,9 @@ impl<'s> Passdata<'s> {
where
T: QueryArgs<'a> + 'a,
R: TryFromConstantArray<'a, Length = T::Length> + 'a,
T::Length: ArrayLength<ValueConversionTy>,
T::Length: ArrayLength<ExpectedConstantTy>,
{
self.schema.validate_tys(predicate, &args.tys())?;
self.schema.validate_conversions(predicate, &args.tys())?;
self.schema
.validate_conversions(predicate, &R::required_tys())?;

Expand Down Expand Up @@ -385,7 +385,7 @@ impl<'s> Passdata<'s> {
pub fn contains_edb<'a, T>(&'a self, pred: &str, args: T) -> Result<bool>
where
T: QueryArgs<'a> + 'a,
T::Length: ArrayLength<ValueConversionTy>,
T::Length: ArrayLength<ExpectedConstantTy>,
{
self.query_edb::<_, VoidResult<T::Length>>(pred, args)
.map(|mut values| values.next().is_some())
Expand All @@ -402,7 +402,7 @@ impl<'s> Passdata<'s> {
where
T: QueryArgs<'a> + 'a,
R: TryFromConstantArray<'a, Length = T::Length> + 'a,
T::Length: ArrayLength<ValueConversionTy>,
T::Length: ArrayLength<ExpectedConstantTy>,
{
let mut iter = self.query_edb(pred, args)?;
let Some(first) = iter.next() else {
Expand Down
33 changes: 11 additions & 22 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ use std::collections::BTreeMap;

use crate::{
error::{Error, ErrorKind, Result},
utils::ValueConversionTy,
utils::ExpectedConstantTy,
Constant,
};

/// Type of a constant
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConstantTy {
/// Unknown
Unknown,
/// Boolean
Bool,
/// Number
Expand All @@ -38,27 +36,18 @@ impl<'a> From<Constant<'a>> for ConstantTy {

impl ConstantTy {
pub(crate) fn is_match(self, other: ConstantTy) -> bool {
if self == other {
return true;
}

if self == Self::Unknown || other == Self::Unknown {
return true;
}

false
self == other
}

pub(crate) fn is_supported(self, other: ValueConversionTy) -> bool {
pub(crate) fn is_supported(self, other: ExpectedConstantTy) -> bool {
match (self, other) {
(ConstantTy::Unknown, _) => unreachable!(),
(_, ValueConversionTy::Any)
| (ConstantTy::Bool, ValueConversionTy::Bool)
| (ConstantTy::Bytes, ValueConversionTy::Bytes)
| (ConstantTy::Num, ValueConversionTy::Num) => true,
(ConstantTy::Bool | ConstantTy::Num, ValueConversionTy::Bytes)
| (ConstantTy::Bool | ConstantTy::Bytes, ValueConversionTy::Num)
| (ConstantTy::Num | ConstantTy::Bytes, ValueConversionTy::Bool) => false,
(_, ExpectedConstantTy::Any)
| (ConstantTy::Bool, ExpectedConstantTy::Bool)
| (ConstantTy::Bytes, ExpectedConstantTy::Bytes)
| (ConstantTy::Num, ExpectedConstantTy::Num) => true,
(ConstantTy::Bool | ConstantTy::Num, ExpectedConstantTy::Bytes)
| (ConstantTy::Bool | ConstantTy::Bytes, ExpectedConstantTy::Num)
| (ConstantTy::Num | ConstantTy::Bytes, ExpectedConstantTy::Bool) => false,
}
}
}
Expand Down Expand Up @@ -128,7 +117,7 @@ impl<'a> Schema<'a> {
pub(crate) fn validate_conversions(
&self,
predicate: &'a str,
actual_tys: &[ValueConversionTy],
actual_tys: &[ExpectedConstantTy],
) -> Result<()> {
let Some(tys) = self.get_tys(predicate) else {
return Err(Error::with_kind(ErrorKind::UnknownPredicate));
Expand Down
Loading

0 comments on commit 2b6d23b

Please sign in to comment.