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