1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#![doc = include_str!("../README.md")]
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;
}
impl<T: Any> Any for &T {
fn is_any(&self) -> bool {
T::is_any(*self)
}
}
impl<T: Any> Any for Option<T> {
fn is_any(&self) -> bool {
match self {
Some(value) => value.is_any(),
None => false,
}
}
}
impl<T: Any> Any for std::sync::Arc<T> {
fn is_any(&self) -> bool {
T::is_any(&**self)
}
}
impl<T: Any> Any for std::rc::Rc<T> {
fn is_any(&self) -> bool {
T::is_any(&**self)
}
}
impl<T: Any> Any for Box<T> {
fn is_any(&self) -> bool {
T::is_any(&**self)
}
}
#[doc(hidden)]
pub mod __internal {
//! Hidden thirdparty dependencies for venndb,
//! not to be relied upon directly, as they may change at any time.
pub use bitvec::{order::Lsb0, slice::IterOnes, vec::BitVec};
pub use hashbrown::HashMap;
/// Generate a random `usize`.
pub fn rand_usize() -> usize {
use rand::Rng;
rand::thread_rng().gen()
}
pub mod hash_map {
//! Internal types related to hash map.
pub use hashbrown::hash_map::Entry;
}
}