From 0d11db69404e504ce80d41821410af20445d0141 Mon Sep 17 00:00:00 2001 From: Harry Maclean Date: Wed, 3 Aug 2022 23:33:54 +1200 Subject: [PATCH] Delegate to inner type for encode_format In the ToSql impls for &T and Option, override encode_format to delegate to the impl for T. This ensures that if T overrides this method, it also overrides it for &T and Option. --- postgres-types/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/postgres-types/src/lib.rs b/postgres-types/src/lib.rs index e912b378..8f758e97 100644 --- a/postgres-types/src/lib.rs +++ b/postgres-types/src/lib.rs @@ -868,6 +868,10 @@ where T::accepts(ty) } + fn encode_format(&self) -> Format { + (*self).encode_format() + } + to_sql_checked!(); } @@ -887,6 +891,13 @@ impl ToSql for Option { ::accepts(ty) } + fn encode_format(&self) -> Format { + match self { + Some(ref val) => val.encode_format(), + None => Format::Binary, + } + } + to_sql_checked!(); }