From 9973fa63572fc8f90da2efd68bfbbc1903c74fb8 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Fri, 20 Mar 2020 19:55:00 -0700 Subject: [PATCH] Add decode_err! to help with formatted decode error generation --- sqlx-core/src/error.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sqlx-core/src/error.rs b/sqlx-core/src/error.rs index 843edd48..68556938 100644 --- a/sqlx-core/src/error.rs +++ b/sqlx-core/src/error.rs @@ -236,6 +236,17 @@ macro_rules! impl_fmt_error { }; } +#[allow(unused_macros)] +macro_rules! decode_err { + ($s:literal, $($args:tt)*) => { + crate::Error::Decode(format!($s, $($args)*).into()) + }; + + ($expr:expr) => { + crate::Error::decode($expr) + }; +} + /// An unexpected `NULL` was encountered during decoding. /// /// Returned from `Row::get` if the value from the database is `NULL`