Skip to content

Commit

Permalink
support filtering based on bool filters
Browse files Browse the repository at this point in the history
  • Loading branch information
GlenDC committed Apr 5, 2024
1 parent b5f7d9e commit 77f9ff6
Show file tree
Hide file tree
Showing 6 changed files with 349 additions and 66 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
bitvec = "1.0.1"
hashbrown = "0.14.3"
venndb-macros = { version = "0.1.0", path = "venndb-macros" }
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
pub use venndb_macros::VennDB;

#[doc(hidden)]
pub mod internal {
pub mod __internal {
//! Hidden thirdparty dependencies for venndb,
//! not to be relied upon directly, as they may change at any time.

pub use bitvec::{bitvec, order::Lsb0, slice::IterOnes, vec::BitVec};
pub use hashbrown::HashMap;
}
20 changes: 20 additions & 0 deletions venndb-macros/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct StructField<'a> {

pub enum FieldInfo<'a> {
Key(KeyField<'a>),
Filter(FilterField<'a>),
}

pub struct KeyField<'a> {
Expand All @@ -48,6 +49,24 @@ impl<'a> KeyField<'a> {
}
}

pub struct FilterField<'a> {
pub name: &'a Ident,
}

impl<'a> FilterField<'a> {
pub fn name(&'a self) -> &'a Ident {
self.name
}

pub fn filter_name(&self) -> Ident {
format_ident!("filter_{}", self.name)
}

pub fn filter_not_name(&self) -> Ident {
format_ident!("filter_not_{}", self.name)
}
}

impl<'a> StructField<'a> {
/// Attempts to parse a field of a `#[derive(VennDB)]` struct, pulling out the
/// fields required for code generation.
Expand All @@ -63,6 +82,7 @@ impl<'a> StructField<'a> {
name: self.name,
ty: &self.field.ty,
}),
FieldKind::Filter => FieldInfo::Filter(FilterField { name: self.name }),
})
}
}

0 comments on commit 77f9ff6

Please sign in to comment.