1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
macro_rules! ser_field { ($serializer:ident, $field:expr, $val_opt:expr) => ( if let Some(f) = $val_opt { try!($serializer.serialize_field($field, &f)); } ) } macro_rules! borrow_fn { ($std_ty:ident) => ( fn borrow<T>(value: &T) -> &$std_ty where T: Borrow<$std_ty> { value.borrow() } ) } macro_rules! impl_mapping_type { ($std_ty:ident, $wrapper_ty:ident, $mapping_ty:ident) => ( impl<M> ::private::field::StdField<$std_ty> for $wrapper_ty<M> where M: $mapping_ty { } impl<M> From<$std_ty> for $wrapper_ty<M> where M: $mapping_ty { fn from(value: $std_ty) -> Self { $wrapper_ty::new(value) } } impl<M> PartialEq<$std_ty> for $wrapper_ty<M> where M: $mapping_ty { fn eq(&self, other: &$std_ty) -> bool { borrow_fn!($std_ty); PartialEq::eq(borrow(&self.value), other) } fn ne(&self, other: &$std_ty) -> bool { borrow_fn!($std_ty); PartialEq::ne(borrow(&self.value), other) } } impl<M> PartialEq<$wrapper_ty<M>> for $std_ty where M: $mapping_ty { fn eq(&self, other: &$wrapper_ty<M>) -> bool { borrow_fn!($std_ty); PartialEq::eq(self, borrow(&other.value)) } fn ne(&self, other: &$wrapper_ty<M>) -> bool { borrow_fn!($std_ty); PartialEq::ne(self, borrow(&other.value)) } } impl<M> ::std::ops::Deref for $wrapper_ty<M> where M: $mapping_ty { type Target = $std_ty; fn deref(&self) -> &$std_ty { borrow_fn!($std_ty); borrow(&self.value) } } impl<M> ::std::borrow::Borrow<$std_ty> for $wrapper_ty<M> where M: $mapping_ty { fn borrow(&self) -> &$std_ty { borrow_fn!($std_ty); borrow(&self.value) } } ); }