diff --git a/postgres/src/lib.rs b/postgres/src/lib.rs index e3a98ae3..b4e4a96c 100644 --- a/postgres/src/lib.rs +++ b/postgres/src/lib.rs @@ -77,8 +77,6 @@ extern crate hex; #[macro_use] extern crate log; extern crate postgres_protocol; -#[macro_use] -#[macro_reexport] extern crate postgres_shared; use fallible_iterator::FallibleIterator; diff --git a/postgres/src/types.rs b/postgres/src/types.rs index c7b3f281..f5ca5873 100644 --- a/postgres/src/types.rs +++ b/postgres/src/types.rs @@ -2,3 +2,36 @@ #[doc(inline)] pub use postgres_shared::types::*; + +/// Generates a simple implementation of `ToSql::accepts` which accepts the +/// types passed to it. +#[macro_export] +macro_rules! accepts { + ($($expected:pat),+) => ( + fn accepts(ty: &$crate::types::Type) -> bool { + match *ty { + $($expected)|+ => true, + _ => false + } + } + ) +} + +/// Generates an implementation of `ToSql::to_sql_checked`. +/// +/// All `ToSql` implementations should use this macro. +#[macro_export] +macro_rules! to_sql_checked { + () => { + fn to_sql_checked(&self, + ty: &$crate::types::Type, + out: &mut ::std::vec::Vec, + ctx: &$crate::types::SessionInfo) + -> ::std::result::Result<$crate::types::IsNull, + Box<::std::error::Error + + ::std::marker::Sync + + ::std::marker::Send>> { + $crate::types::__to_sql_checked(self, ty, out, ctx) + } + } +}