Skip to content

Commit

Permalink
add ::venndb::Any trait + example
Browse files Browse the repository at this point in the history
  • Loading branch information
glendc committed Apr 15, 2024
1 parent 84c0f40 commit 307d6b8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand Down
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ <h2>Example</h2>
is_admin: bool,
#[venndb(skip)]
foo: bool,
#[venndb(filter)]
#[venndb(filter, any)]
department: Department,
#[venndb(filter)]
country: Option&lt;String&gt;,
Expand Down

0 comments on commit 307d6b8

Please sign in to comment.