1#[macro_export]
2macro_rules! new_cache {
32 () => {{
33 let files: Vec<String> = Vec::new();
34 $crate::cache::Cache::new(&files)
35 }};
36 ($slice:expr) => {{ $crate::cache::Cache::new($slice) }};
37}
38
39macro_rules! raw_iter {
41 ($($ty:ty => $iter:ident),* $(,)?) => {$(
42 #[doc = concat!("Iterator Struct for [`", stringify!($ty), "`].")]
43 pub struct $iter(UniquePtr<$ty>);
44
45 impl Iterator for $iter {
46 type Item = UniquePtr<$ty>;
47
48 fn next(&mut self) -> Option<Self::Item> {
49 if self.0.end() {
50 None
51 } else {
52 let ptr = unsafe { self.0.unique() };
53 self.0.pin_mut().raw_next();
54 Some(ptr)
55 }
56 }
57 }
58
59 impl IntoRawIter for UniquePtr<$ty> {
60 type Item = $iter;
61
62 fn raw_iter(self) -> Self::Item { $iter(self) }
63
64 fn make_safe(self) -> Option<Self> { if self.end() { None } else { Some(self) } }
65
66 fn to_vec(self) -> Vec<Self> { self.raw_iter().collect() }
67 }
68 )*};
69}
70
71macro_rules! cxx_convert_result {
74 ($wrapper:ident, $($(#[$meta:meta])* $method:ident ( $( $arg:ident : $arg_ty:ty ),* ) -> $ret:ty ),* $(,)? ) => {
75 impl<'a> $wrapper<'a> {
76 $(
77 $(#[$meta])*
78 pub fn $method(&self, $( $arg : $arg_ty ),* ) -> Option<$ret> {
79 self.ptr.$method($( $arg ),*).ok()
80 }
81 )*
82 }
83 };
84}
85
86macro_rules! impl_partial_eq {
87 ($($wrapper:ident $(<$lt:lifetime>)?),* $(,)?) => {
88 $(
89 impl $(<$lt>)? PartialEq for $wrapper $(<$lt>)? {
90 fn eq(&self, other: &Self) -> bool { self.index() == other.index() }
91 }
92 )*
93 };
94}
95
96macro_rules! impl_hash_eq {
97 ($($wrapper:ident $(<$lt:lifetime>)?),* $(,)?) => {
98 $(
99 impl $(<$lt>)? std::hash::Hash for $wrapper $(<$lt>)? {
100 fn hash<H: std::hash::Hasher>(&self, state: &mut H) { self.index().hash(state); }
101 }
102
103 impl $(<$lt>)? Eq for $wrapper $(<$lt>)? {}
104 )*
105 };
106}
107
108macro_rules! impl_deref {
110 ($($wrapper:ident $(<$lt:lifetime>)? -> $target:ty),* $(,)?) => {
111 $(
112 impl $(<$lt>)? std::ops::Deref for $wrapper $(<$lt>)? {
113 type Target = $target;
114
115 #[inline]
116 fn deref(&self) -> &Self::Target {
117 &self.ptr
118 }
119 }
120 )*
121 };
122}