Skip to content

Commit b6521ae

Browse files
committed
chore: more macro's
1 parent 7c3b76b commit b6521ae

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

sqlx-core/src/decode.rs

+16-31
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,24 @@ where
8282
}
8383
}
8484

85-
// implement `Decode` for Arc<T> for all SQL types
86-
impl<'r, DB, T> Decode<'r, DB> for Arc<T>
87-
where
88-
DB: Database,
89-
T: Decode<'r, DB>,
90-
{
91-
fn decode(value: <DB as Database>::ValueRef<'r>) -> Result<Self, BoxDynError> {
92-
Ok(Arc::new(T::decode(value)?))
93-
}
85+
macro_rules! impl_decode_for_smartpointer {
86+
($smart_pointer:ty) => {
87+
impl<'r, DB, T> Decode<'r, DB> for $smart_pointer
88+
where
89+
DB: Database,
90+
T: Decode<'r, DB>,
91+
{
92+
fn decode(value: <DB as Database>::ValueRef<'r>) -> Result<Self, BoxDynError> {
93+
Ok(Self::new(T::decode(value)?))
94+
}
95+
}
96+
};
9497
}
9598

99+
impl_decode_for_smartpointer!(Arc<T>);
100+
impl_decode_for_smartpointer!(Box<T>);
101+
impl_decode_for_smartpointer!(Rc<T>);
102+
96103
// implement `Decode` for Cow<T> for all SQL types
97104
impl<'r, DB, T> Decode<'r, DB> for Cow<'_, T>
98105
where
@@ -104,25 +111,3 @@ where
104111
Ok(Cow::Owned(T::decode(value)?))
105112
}
106113
}
107-
108-
// implement `Decode` for Box<T> for all SQL types
109-
impl<'r, DB, T> Decode<'r, DB> for Box<T>
110-
where
111-
DB: Database,
112-
T: Decode<'r, DB>,
113-
{
114-
fn decode(value: <DB as Database>::ValueRef<'r>) -> Result<Self, BoxDynError> {
115-
Ok(Box::new(T::decode(value)?))
116-
}
117-
}
118-
119-
// implement `Decode` for Rc<T> for all SQL types
120-
impl<'r, DB, T> Decode<'r, DB> for Rc<T>
121-
where
122-
DB: Database,
123-
T: Decode<'r, DB>,
124-
{
125-
fn decode(value: <DB as Database>::ValueRef<'r>) -> Result<Self, BoxDynError> {
126-
Ok(Rc::new(T::decode(value)?))
127-
}
128-
}

0 commit comments

Comments
 (0)