@@ -82,11 +82,11 @@ pub enum Format {
8282 Binary = 1
8383}
8484
85- macro_rules! check_oid (
86- ( $( $expected: ident ) |+, $actual: ident) => (
85+ macro_rules! check_types (
86+ ( $( $expected: pat ) |+, $actual: ident) => (
8787 match $actual {
8888 $( $expected) |+ => ( ) ,
89- actual => fail !( "Invalid Oid %? " , actual)
89+ actual => fail2 !( "Invalid Postgres type {:?} " , actual)
9090 }
9191 )
9292)
@@ -96,19 +96,19 @@ pub trait FromSql {
9696}
9797
9898macro_rules! from_map_impl(
99- ( $( $oid : ident ) |+, $t: ty, $blk: expr) => (
99+ ( $( $expected : pat ) |+, $t: ty, $blk: expr) => (
100100 impl FromSql for Option <$t> {
101101 fn from_sql( ty: PostgresType , raw: & Option <~[ u8 ] >) -> Option <$t> {
102- check_oid !( $( $oid ) |+, ty)
102+ check_types !( $( $expected ) |+, ty)
103103 raw. map( $blk)
104104 }
105105 }
106106 )
107107)
108108
109109macro_rules! from_conversions_impl(
110- ( $oid : ident , $t: ty, $f: ident) => (
111- from_map_impl!( $oid , $t, |buf| {
110+ ( $expected : pat , $t: ty, $f: ident) => (
111+ from_map_impl!( $expected , $t, |buf| {
112112 let mut reader = BufReader :: new( buf. as_slice( ) ) ;
113113 reader. $f( )
114114 } )
@@ -150,7 +150,7 @@ from_option_impl!(~str)
150150
151151impl FromSql for Option < ~[ u8 ] > {
152152 fn from_sql ( ty : PostgresType , raw : & Option < ~[ u8 ] > ) -> Option < ~[ u8 ] > {
153- check_oid ! ( PgByteA , ty)
153+ check_types ! ( PgByteA , ty)
154154 raw. clone ( )
155155 }
156156}
@@ -174,7 +174,7 @@ macro_rules! to_option_impl(
174174 ( $( $oid: ident) |+, $t: ty) => (
175175 impl ToSql for Option <$t> {
176176 fn to_sql( & self , ty: PostgresType ) -> ( Format , Option <~[ u8 ] >) {
177- check_oid !( $( $oid) |+, ty)
177+ check_types !( $( $oid) |+, ty)
178178
179179 match * self {
180180 None => ( Text , None ) ,
@@ -186,7 +186,7 @@ macro_rules! to_option_impl(
186186 ( self , $( $oid: ident) |+, $t: ty) => (
187187 impl <' self > ToSql for Option <$t> {
188188 fn to_sql( & self , ty: PostgresType ) -> ( Format , Option <~[ u8 ] >) {
189- check_oid !( $( $oid) |+, ty)
189+ check_types !( $( $oid) |+, ty)
190190
191191 match * self {
192192 None => ( Text , None ) ,
@@ -201,7 +201,7 @@ macro_rules! to_conversions_impl(
201201 ( $( $oid: ident) |+, $t: ty, $f: ident) => (
202202 impl ToSql for $t {
203203 fn to_sql( & self , ty: PostgresType ) -> ( Format , Option <~[ u8 ] >) {
204- check_oid !( $( $oid) |+, ty)
204+ check_types !( $( $oid) |+, ty)
205205
206206 let mut writer = MemWriter :: new( ) ;
207207 writer. $f( * self ) ;
@@ -213,7 +213,7 @@ macro_rules! to_conversions_impl(
213213
214214impl ToSql for bool {
215215 fn to_sql ( & self , ty : PostgresType ) -> ( Format , Option < ~[ u8 ] > ) {
216- check_oid ! ( PgBool , ty)
216+ check_types ! ( PgBool , ty)
217217 ( Binary , Some ( ~[ * self as u8 ] ) )
218218 }
219219}
@@ -234,14 +234,14 @@ to_option_impl!(PgFloat8, f64)
234234
235235impl ToSql for ~str {
236236 fn to_sql ( & self , ty : PostgresType ) -> ( Format , Option < ~[ u8 ] > ) {
237- check_oid ! ( PgVarchar | PgText | PgCharN , ty)
237+ check_types ! ( PgVarchar | PgText | PgCharN , ty)
238238 ( Text , Some ( self . as_bytes ( ) . to_owned ( ) ) )
239239 }
240240}
241241
242242impl < ' self > ToSql for & ' self str {
243243 fn to_sql ( & self , ty : PostgresType ) -> ( Format , Option < ~[ u8 ] > ) {
244- check_oid ! ( PgVarchar | PgText | PgCharN , ty)
244+ check_types ! ( PgVarchar | PgText | PgCharN , ty)
245245 ( Text , Some ( self . as_bytes ( ) . to_owned ( ) ) )
246246 }
247247}
@@ -251,14 +251,14 @@ to_option_impl!(self, PgVarchar | PgText | PgCharN, &'self str)
251251
252252impl ToSql for ~[ u8 ] {
253253 fn to_sql ( & self , ty : PostgresType ) -> ( Format , Option < ~[ u8 ] > ) {
254- check_oid ! ( PgByteA , ty)
254+ check_types ! ( PgByteA , ty)
255255 ( Binary , Some ( self . to_owned ( ) ) )
256256 }
257257}
258258
259259impl < ' self > ToSql for & ' self [ u8 ] {
260260 fn to_sql ( & self , ty : PostgresType ) -> ( Format , Option < ~[ u8 ] > ) {
261- check_oid ! ( PgByteA , ty)
261+ check_types ! ( PgByteA , ty)
262262 ( Binary , Some ( self . to_owned ( ) ) )
263263 }
264264}
@@ -268,7 +268,7 @@ to_option_impl!(self, PgByteA, &'self [u8])
268268
269269impl ToSql for Json {
270270 fn to_sql ( & self , ty : PostgresType ) -> ( Format , Option < ~[ u8 ] > ) {
271- check_oid ! ( PgJson , ty)
271+ check_types ! ( PgJson , ty)
272272 ( Text , Some ( self . to_str ( ) . into_bytes ( ) ) )
273273 }
274274}
@@ -277,7 +277,7 @@ to_option_impl!(PgJson, Json)
277277
278278impl ToSql for Uuid {
279279 fn to_sql ( & self , ty : PostgresType ) -> ( Format , Option < ~[ u8 ] > ) {
280- check_oid ! ( PgUuid , ty)
280+ check_types ! ( PgUuid , ty)
281281 ( Binary , Some ( self . to_bytes ( ) . to_owned ( ) ) )
282282 }
283283}
0 commit comments