Skip to content

Commit d650adb

Browse files
authored
Merge pull request sfackler#928 from hmac/hmac/encode-format
Delegate encode_format to T in &T and Option<T>
2 parents d7b10f2 + 17da499 commit d650adb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

postgres-types/src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ pub trait ToSql: fmt::Debug {
844844
/// Supported Postgres message format types
845845
///
846846
/// Using Text format in a message assumes a Postgres `SERVER_ENCODING` of `UTF8`
847+
#[derive(Clone, Copy, Debug)]
847848
pub enum Format {
848849
/// Text format (UTF-8)
849850
Text,
@@ -867,6 +868,10 @@ where
867868
T::accepts(ty)
868869
}
869870

871+
fn encode_format(&self) -> Format {
872+
(*self).encode_format()
873+
}
874+
870875
to_sql_checked!();
871876
}
872877

@@ -886,6 +891,13 @@ impl<T: ToSql> ToSql for Option<T> {
886891
<T as ToSql>::accepts(ty)
887892
}
888893

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

0 commit comments

Comments
 (0)