Delegate to inner type for encode_format

In the ToSql impls for &T and Option<T>, 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<T>.
This commit is contained in:
Harry Maclean 2022-08-03 23:33:54 +12:00
parent f048f39812
commit 0d11db6940

View File

@ -868,6 +868,10 @@ where
T::accepts(ty)
}
fn encode_format(&self) -> Format {
(*self).encode_format()
}
to_sql_checked!();
}
@ -887,6 +891,13 @@ impl<T: ToSql> ToSql for Option<T> {
<T as ToSql>::accepts(ty)
}
fn encode_format(&self) -> Format {
match self {
Some(ref val) => val.encode_format(),
None => Format::Binary,
}
}
to_sql_checked!();
}