Skip to content

Commit 0d11db6

Browse files
committed
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>.
1 parent f048f39 commit 0d11db6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

postgres-types/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,10 @@ where
868868
T::accepts(ty)
869869
}
870870

871+
fn encode_format(&self) -> Format {
872+
(*self).encode_format()
873+
}
874+
871875
to_sql_checked!();
872876
}
873877

@@ -887,6 +891,13 @@ impl<T: ToSql> ToSql for Option<T> {
887891
<T as ToSql>::accepts(ty)
888892
}
889893

894+
fn encode_format(&self) -> Format {
895+
match self {
896+
Some(ref val) => val.encode_format(),
897+
None => Format::Binary,
898+
}
899+
}
900+
890901
to_sql_checked!();
891902
}
892903

0 commit comments

Comments
 (0)