@@ -176,3 +176,44 @@ impl<'r> ValueRef<'r> for AnyValueRef<'r> {
176176 }
177177 }
178178}
179+
180+ macro_rules! impl_try_from_any_value_ref {
181+ ( $(
182+ #[ cfg( feature = $feature: literal) ]
183+ $db_name: ident => $value_ref: ty,
184+ ) * ) => {
185+ $(
186+ #[ cfg( feature = $feature) ]
187+ impl <' r> TryFrom <AnyValueRef <' r>> for $value_ref {
188+ type Error = crate :: error:: Error ;
189+
190+ fn try_from( value: AnyValueRef <' r>) -> Result <Self , Self :: Error > {
191+ #[ allow( unreachable_patterns) ]
192+ match value. kind {
193+ AnyValueRefKind :: $db_name( value) => Ok ( value) ,
194+ _ => Err ( crate :: error:: Error :: Configuration (
195+ format!( "Expected {}, got {:?}" , stringify!( $value_ref) , value. type_info( ) ) . into( ) ,
196+ ) ) ,
197+ }
198+ }
199+ }
200+ ) *
201+ } ;
202+ }
203+
204+ impl_try_from_any_value_ref ! {
205+ #[ cfg( feature = "postgres" ) ]
206+ Postgres => PgValueRef <' r>,
207+
208+ #[ cfg( feature = "mysql" ) ]
209+ MySql => MySqlValueRef <' r>,
210+
211+ #[ cfg( feature = "sqlite" ) ]
212+ Sqlite => SqliteValueRef <' r>,
213+
214+ #[ cfg( feature = "mssql" ) ]
215+ Mssql => MssqlValueRef <' r>,
216+
217+ #[ cfg( feature = "odbc" ) ]
218+ Odbc => OdbcValueRef <' r>,
219+ }
0 commit comments