|
1 | 1 | //! Provides [`Encode`] for encoding values for the database.
|
2 | 2 |
|
| 3 | +use std::borrow::Cow; |
3 | 4 | use std::mem;
|
| 5 | +use std::sync::Arc; |
4 | 6 |
|
5 | 7 | use crate::database::Database;
|
6 | 8 | use crate::error::BoxDynError;
|
@@ -129,3 +131,88 @@ macro_rules! impl_encode_for_option {
|
129 | 131 | }
|
130 | 132 | };
|
131 | 133 | }
|
| 134 | + |
| 135 | +impl<'q, T, DB: Database> Encode<'q, DB> for Arc<T> |
| 136 | +where |
| 137 | + T: Encode<'q, DB>, |
| 138 | +{ |
| 139 | + #[inline] |
| 140 | + fn encode(self, buf: &mut <DB as Database>::ArgumentBuffer<'q>) -> Result<IsNull, BoxDynError> { |
| 141 | + <T as Encode<DB>>::encode_by_ref(self.as_ref(), buf) |
| 142 | + } |
| 143 | + |
| 144 | + #[inline] |
| 145 | + fn encode_by_ref( |
| 146 | + &self, |
| 147 | + buf: &mut <DB as Database>::ArgumentBuffer<'q>, |
| 148 | + ) -> Result<IsNull, BoxDynError> { |
| 149 | + <&T as Encode<DB>>::encode(self, buf) |
| 150 | + } |
| 151 | + |
| 152 | + #[inline] |
| 153 | + fn produces(&self) -> Option<DB::TypeInfo> { |
| 154 | + (**self).produces() |
| 155 | + } |
| 156 | + |
| 157 | + #[inline] |
| 158 | + fn size_hint(&self) -> usize { |
| 159 | + (**self).size_hint() |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | +impl<'q, T, DB: Database> Encode<'q, DB> for Cow<'_, T> |
| 164 | +where |
| 165 | + T: Encode<'q, DB>, |
| 166 | + T: ToOwned<Owned = T>, |
| 167 | +{ |
| 168 | + #[inline] |
| 169 | + fn encode(self, buf: &mut <DB as Database>::ArgumentBuffer<'q>) -> Result<IsNull, BoxDynError> { |
| 170 | + <T as Encode<DB>>::encode_by_ref(self.as_ref(), buf) |
| 171 | + } |
| 172 | + |
| 173 | + #[inline] |
| 174 | + fn encode_by_ref( |
| 175 | + &self, |
| 176 | + buf: &mut <DB as Database>::ArgumentBuffer<'q>, |
| 177 | + ) -> Result<IsNull, BoxDynError> { |
| 178 | + <&T as Encode<DB>>::encode(self, buf) |
| 179 | + } |
| 180 | + |
| 181 | + #[inline] |
| 182 | + fn produces(&self) -> Option<DB::TypeInfo> { |
| 183 | + (**self).produces() |
| 184 | + } |
| 185 | + |
| 186 | + #[inline] |
| 187 | + fn size_hint(&self) -> usize { |
| 188 | + (**self).size_hint() |
| 189 | + } |
| 190 | +} |
| 191 | + |
| 192 | +impl<'q, T, DB: Database> Encode<'q, DB> for Box<T> |
| 193 | +where |
| 194 | + T: Encode<'q, DB>, |
| 195 | +{ |
| 196 | + #[inline] |
| 197 | + fn encode(self, buf: &mut <DB as Database>::ArgumentBuffer<'q>) -> Result<IsNull, BoxDynError> { |
| 198 | + <T as Encode<DB>>::encode_by_ref(self.as_ref(), buf) |
| 199 | + } |
| 200 | + |
| 201 | + #[inline] |
| 202 | + fn encode_by_ref( |
| 203 | + &self, |
| 204 | + buf: &mut <DB as Database>::ArgumentBuffer<'q>, |
| 205 | + ) -> Result<IsNull, BoxDynError> { |
| 206 | + <&T as Encode<DB>>::encode(self, buf) |
| 207 | + } |
| 208 | + |
| 209 | + #[inline] |
| 210 | + fn produces(&self) -> Option<DB::TypeInfo> { |
| 211 | + (**self).produces() |
| 212 | + } |
| 213 | + |
| 214 | + #[inline] |
| 215 | + fn size_hint(&self) -> usize { |
| 216 | + (**self).size_hint() |
| 217 | + } |
| 218 | +} |
0 commit comments