Skip to content

Commit d0db938

Browse files
committed
Forward macros
1 parent 178d119 commit d0db938

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

postgres/src/macros.rs

+32
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,35 @@ macro_rules! debug {
3535
macro_rules! info {
3636
($($t:tt)*) => {}
3737
}
38+
39+
/// Generates a simple implementation of `ToSql::accepts` which accepts the
40+
/// types passed to it.
41+
#[macro_export]
42+
macro_rules! accepts {
43+
($($expected:pat),+) => (
44+
fn accepts(ty: &$crate::types::Type) -> bool {
45+
match *ty {
46+
$($expected)|+ => true,
47+
_ => false
48+
}
49+
}
50+
)
51+
}
52+
53+
/// Generates an implementation of `ToSql::to_sql_checked`.
54+
///
55+
/// All `ToSql` implementations should use this macro.
56+
#[macro_export]
57+
macro_rules! to_sql_checked {
58+
() => {
59+
fn to_sql_checked(&self,
60+
ty: &$crate::types::Type,
61+
out: &mut ::std::vec::Vec<u8>)
62+
-> ::std::result::Result<$crate::types::IsNull,
63+
Box<::std::error::Error +
64+
::std::marker::Sync +
65+
::std::marker::Send>> {
66+
$crate::types::__to_sql_checked(self, ty, out)
67+
}
68+
}
69+
}

tokio-postgres/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ use transaction::Transaction;
101101
use types::{Oid, Type, ToSql, IsNull, FromSql, Kind, Field, NAME, CHAR, OID};
102102
use rows::Row;
103103

104+
#[macro_use]
105+
mod macros;
104106
pub mod rows;
105107
pub mod stmt;
106108
mod sink;

tokio-postgres/src/macros.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// Generates a simple implementation of `ToSql::accepts` which accepts the
2+
/// types passed to it.
3+
#[macro_export]
4+
macro_rules! accepts {
5+
($($expected:pat),+) => (
6+
fn accepts(ty: &$crate::types::Type) -> bool {
7+
match *ty {
8+
$($expected)|+ => true,
9+
_ => false
10+
}
11+
}
12+
)
13+
}
14+
15+
/// Generates an implementation of `ToSql::to_sql_checked`.
16+
///
17+
/// All `ToSql` implementations should use this macro.
18+
#[macro_export]
19+
macro_rules! to_sql_checked {
20+
() => {
21+
fn to_sql_checked(&self,
22+
ty: &$crate::types::Type,
23+
out: &mut ::std::vec::Vec<u8>)
24+
-> ::std::result::Result<$crate::types::IsNull,
25+
Box<::std::error::Error +
26+
::std::marker::Sync +
27+
::std::marker::Send>> {
28+
$crate::types::__to_sql_checked(self, ty, out)
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)