Skip to content

0.2.1

Compare
Choose a tag to compare
@GlenDC GlenDC released this 15 Apr 21:06
· 14 commits to main since this release
389fb94

A backwards compatible patch for v0.2.0
to support rows that allow any value for a specific column.

Non-Breaking changes:

  • support #[venndb(any)] filters;
    • these are possible only for T filter maps, where T: ::venndb::Any;
    • bool filters cannot be any as bool doesn't implement the ::venndb::Any trait;
    • rows that are any will match regardless of the query filter used for that property;

Example usage:

use venndb::{Any, VennDB};
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub enum Department {
  Any,
  Hr,
  Engineering,
}

impl Any for Department {
  fn is_any(&self) -> bool {
    self == Department::Any
  }
}

#[derive(Debug, VennDB)]
pub struct Employee {
  name: String,
  #[venndb(filter, any)]
  department: Department,
}

let db = EmployeeDB::from_iter([
  Employee { name: "Jack".to_owned(), department: Department::Any },
  Employee { name: "Derby".to_owned(), department: Department::Hr },
]);
let mut query = db.query();

// will match Jack and Derby, as Jack is marked as Any, meaning it can work for w/e value
let hr_employees: Vec<_> = query.department(Department::Hr).execute().unwrap().iter().collect();
assert_eq!(hr_employees.len(), 2);

In case you combine it with the filter map property being optional (department: Option<Department>),
then it will still work the same, where rows with None are seen as nothing at all and just ignored.
This has no affect on the correct functioning of Any.