Implement Deref and DerefMut for built-in extractors (#1922)

This commit is contained in:
David Pedersen
2023-04-10 07:18:35 +00:00
committed by GitHub
parent 43b2d52403
commit 352cf9a266
17 changed files with 67 additions and 112 deletions
+41
View File
@@ -171,3 +171,44 @@ macro_rules! all_the_tuples_no_last_special_case {
$name!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16);
};
}
/// Private API.
#[doc(hidden)]
#[macro_export]
macro_rules! __impl_deref {
($ident:ident) => {
impl<T> std::ops::Deref for $ident<T> {
type Target = T;
#[inline]
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> std::ops::DerefMut for $ident<T> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
};
($ident:ident: $ty:ty) => {
impl std::ops::Deref for $ident {
type Target = $ty;
#[inline]
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl std::ops::DerefMut for $ident {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
};
}