diff --git a/README.md b/README.md index e989c5a..d7a8e7c 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ pub struct Employee { is_admin: bool, #[venndb(skip)] foo: bool, - #[venndb(filter)] + #[venndb(filter, any)] department: Department, #[venndb(filter)] country: Option, diff --git a/src/lib.rs b/src/lib.rs index cda97e8..39591d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,33 @@ pub use venndb_macros::VennDB; +/// A trait that types can implement in order to support `#[venndb(any)]` attribute filters. +pub trait Any { + /// Returns true if the value is considered to be "any" within the context of the type. + /// + /// # Example + /// + /// ``` + /// use venndb::Any; + /// + /// #[derive(Debug)] + /// struct MyString(String); + /// + /// impl Any for MyString { + /// fn is_any(&self) -> bool { + /// self.0 == "*" + /// } + /// } + /// + /// let my_string = MyString("*".to_string()); + /// assert!(my_string.is_any()); + /// + /// let my_string = MyString("hello".to_string()); + /// assert!(!my_string.is_any()); + /// ``` + fn is_any(&self) -> bool; +} + #[doc(hidden)] pub mod __internal { //! Hidden thirdparty dependencies for venndb, diff --git a/www/index.html b/www/index.html index 1110d51..ff122fd 100644 --- a/www/index.html +++ b/www/index.html @@ -123,7 +123,7 @@

Example

is_admin: bool, #[venndb(skip)] foo: bool, - #[venndb(filter)] + #[venndb(filter, any)] department: Department, #[venndb(filter)] country: Option<String>,