#[macro_export]
macro_rules! new_cache {
() => {{
let files: Vec<String> = Vec::new();
$crate::cache::Cache::new(&files)
}};
($slice:expr) => {{ $crate::cache::Cache::new($slice) }};
}
macro_rules! raw_iter {
($($ty:ty => $iter:ident),* $(,)?) => {$(
#[doc = concat!("Iterator Struct for [`", stringify!($ty), "`].")]
pub struct $iter(UniquePtr<$ty>);
impl Iterator for $iter {
type Item = UniquePtr<$ty>;
fn next(&mut self) -> Option<Self::Item> {
if self.0.end() {
None
} else {
let ptr = unsafe { self.0.unique() };
self.0.pin_mut().raw_next();
Some(ptr)
}
}
}
impl IntoRawIter for UniquePtr<$ty> {
type Item = $iter;
fn raw_iter(self) -> Self::Item { $iter(self) }
fn make_safe(self) -> Option<Self> { if self.end() { None } else { Some(self) } }
fn to_vec(self) -> Vec<Self> { self.raw_iter().collect() }
}
)*};
}
macro_rules! cxx_convert_result {
($wrapper:ident, $($(#[$meta:meta])* $method:ident ( $( $arg:ident : $arg_ty:ty ),* ) -> $ret:ty ),* $(,)? ) => {
impl<'a> $wrapper<'a> {
$(
$(#[$meta])*
pub fn $method(&self, $( $arg : $arg_ty ),* ) -> Option<$ret> {
self.ptr.$method($( $arg ),*).ok()
}
)*
}
};
}
macro_rules! impl_partial_eq {
($($wrapper:ident $(<$lt:lifetime>)?),* $(,)?) => {
$(
impl $(<$lt>)? PartialEq for $wrapper $(<$lt>)? {
fn eq(&self, other: &Self) -> bool { self.index() == other.index() }
}
)*
};
}
macro_rules! impl_hash_eq {
($($wrapper:ident $(<$lt:lifetime>)?),* $(,)?) => {
$(
impl $(<$lt>)? std::hash::Hash for $wrapper $(<$lt>)? {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { self.index().hash(state); }
}
impl $(<$lt>)? Eq for $wrapper $(<$lt>)? {}
)*
};
}
macro_rules! impl_deref {
($($wrapper:ident $(<$lt:lifetime>)? -> $target:ty),* $(,)?) => {
$(
impl $(<$lt>)? std::ops::Deref for $wrapper $(<$lt>)? {
type Target = $target;
#[inline]
fn deref(&self) -> &Self::Target {
&self.ptr
}
}
)*
};
}