graphql_starter/
macros.rs1#[macro_export]
3macro_rules! newtype {
4 ($(#[$attr:meta])* $new_v:vis $new_ty:ident $(< $($gen:ident$(: $gen_ty:path)?),* >)? ($v:vis $ty:path)) => {
5 $(#[$attr])*
6 $new_v struct $new_ty$(<$($gen$(: $gen_ty)?),*>)?($v $ty);
7 $crate::newtype_impl!($new_ty$(<$($gen$(: $gen_ty)?),*>)?($ty));
8 };
9}
10
11#[macro_export]
13macro_rules! newtype_impl {
14 ($new_ty:ident $(< $($gen:ident$(: $gen_ty:path)?),* >)? ($ty:path)) => {
15 impl$(<$($gen$(: $gen_ty)?),*>)? From<$ty> for $new_ty$(<$($gen),*>)? {
16 fn from(o: $ty) -> Self {
17 $new_ty(o)
18 }
19 }
20 impl$(<$($gen$(: $gen_ty)?),*>)? From<$new_ty$(<$($gen),*>)?> for $ty {
21 fn from(o: $new_ty$(<$($gen),*>)?) -> Self {
22 o.0
23 }
24 }
25 impl$(<$($gen$(: $gen_ty)?),*>)? ::std::ops::Deref for $new_ty$(<$($gen),*>)? {
26 type Target = $ty;
27
28 fn deref(&self) -> &Self::Target {
29 &self.0
30 }
31 }
32 impl$(<$($gen$(: $gen_ty)?),*>)? ::std::ops::DerefMut for $new_ty$(<$($gen),*>)? {
33 fn deref_mut(&mut self) -> &mut Self::Target {
34 &mut self.0
35 }
36 }
37 };
38}
39
40#[macro_export]
60macro_rules! using {
61 ($($v:vis $p:ident),* $(,)?) => {
62 $(
63 mod $p;
64 $v use self::$p::*;
65 )*
66 }
67}