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