@@ -8,7 +8,7 @@ use postgres::types::{RawFromSql, RawToSql};
88use { postgres, Range , RangeBound , BoundType , BoundSided , Normalizable } ;
99
1010macro_rules! check_types {
11- ( $( $expected: pat) |+ , $actual : ident ) => (
11+ ( $actual : ident , $ ( $expected: pat) ,+ ) => (
1212 match $actual {
1313 $( & $expected) |+ => { }
1414 actual => return Err ( :: postgres:: Error :: WrongType ( actual. clone( ) ) )
@@ -17,10 +17,10 @@ macro_rules! check_types {
1717}
1818
1919macro_rules! from_sql_impl {
20- ( $( $oid: pat) |+ , $t : ty ) => {
20+ ( $t : ty , $ ( $oid: pat) ,+ ) => {
2121 impl :: postgres:: FromSql for Option <:: Range <$t>> {
2222 fn from_sql( ty: & :: postgres:: Type , raw: Option <& [ u8 ] >) -> :: postgres:: Result <Self > {
23- check_types!( $( $oid) |+ , ty ) ;
23+ check_types!( ty , $( $oid) ,+ ) ;
2424
2525 match raw {
2626 Some ( mut raw) => :: postgres:: types:: RawFromSql :: raw_from_sql( & mut raw) . map( Some ) ,
@@ -43,10 +43,10 @@ macro_rules! from_sql_impl {
4343}
4444
4545macro_rules! to_sql_impl {
46- ( $( $oid: pat) |+ , $t : ty ) => {
46+ ( $t : ty , $ ( $oid: pat) ,+ ) => {
4747 impl :: postgres:: ToSql for :: Range <$t> {
4848 fn to_sql( & self , ty: & :: postgres:: Type ) -> :: postgres:: Result <Option <Vec <u8 >>> {
49- check_types!( $( $oid) |+ , ty ) ;
49+ check_types!( ty , $( $oid) ,+ ) ;
5050
5151 let mut writer = vec![ ] ;
5252 try!( self . raw_to_sql( & mut writer) ) ;
@@ -56,7 +56,7 @@ macro_rules! to_sql_impl {
5656
5757 impl :: postgres:: ToSql for Option <:: Range <$t>> {
5858 fn to_sql( & self , ty: & :: postgres:: Type ) -> :: postgres:: Result <Option <Vec <u8 >>> {
59- check_types!( $( $oid) |+ , ty ) ;
59+ check_types!( ty , $( $oid) ,+ ) ;
6060 match * self {
6161 Some ( ref arr) => arr. to_sql( ty) ,
6262 None => Ok ( None )
@@ -89,7 +89,7 @@ impl<T> RawFromSql for Range<T> where T: PartialOrd+Normalizable+RawFromSql {
8989 0 => BoundType :: Exclusive ,
9090 _ => BoundType :: Inclusive ,
9191 } ;
92- let len = try!( rdr. read_be_i32 ( ) ) as uint ;
92+ let len = try!( rdr. read_be_i32 ( ) ) as usize ;
9393 let mut limit = LimitReader :: new ( rdr. by_ref ( ) , len) ;
9494 let bound = try!( RawFromSql :: raw_from_sql ( & mut limit) ) ;
9595 if limit. limit ( ) != 0 {
@@ -107,9 +107,9 @@ impl<T> RawFromSql for Range<T> where T: PartialOrd+Normalizable+RawFromSql {
107107 }
108108}
109109
110- from_sql_impl ! ( Type :: Int4Range , i32 ) ;
111- from_sql_impl ! ( Type :: Int8Range , i64 ) ;
112- from_sql_impl ! ( Type :: TsRange | Type :: TstzRange , Timespec ) ;
110+ from_sql_impl ! ( i32 , Type :: Int4Range ) ;
111+ from_sql_impl ! ( i64 , Type :: Int8Range ) ;
112+ from_sql_impl ! ( Timespec , Type :: TsRange , Type :: TstzRange ) ;
113113
114114impl < T > RawToSql for Range < T > where T : PartialOrd +Normalizable +RawToSql {
115115 fn raw_to_sql < W : Writer > ( & self , buf : & mut W ) -> postgres:: Result < ( ) > {
@@ -149,9 +149,9 @@ impl<T> RawToSql for Range<T> where T: PartialOrd+Normalizable+RawToSql {
149149 }
150150}
151151
152- to_sql_impl ! ( Type :: Int4Range , i32 ) ;
153- to_sql_impl ! ( Type :: Int8Range , i64 ) ;
154- to_sql_impl ! ( Type :: TsRange | Type :: TstzRange , Timespec ) ;
152+ to_sql_impl ! ( i32 , Type :: Int4Range ) ;
153+ to_sql_impl ! ( i64 , Type :: Int8Range ) ;
154+ to_sql_impl ! ( Timespec , Type :: TsRange , Type :: TstzRange ) ;
155155
156156#[ cfg( test) ]
157157mod test {
@@ -162,34 +162,34 @@ mod test {
162162
163163 macro_rules! test_range {
164164 ( $name: expr, $t: ty, $low: expr, $low_str: expr, $high: expr, $high_str: expr) => ( {
165- let tests = & [ ( Some ( range!( '(' , ')' ) ) , "'(,)'" . to_string( ) ) ,
166- ( Some ( range!( '[' $low, ')' ) ) , format!( "'[{},)'" , $low_str) ) ,
167- ( Some ( range!( '(' $low, ')' ) ) , format!( "'({},)'" , $low_str) ) ,
168- ( Some ( range!( '(' , $high ']' ) ) , format!( "'(,{}]'" , $high_str) ) ,
169- ( Some ( range!( '(' , $high ')' ) ) , format!( "'(,{})'" , $high_str) ) ,
170- ( Some ( range!( '[' $low, $high ']' ) ) ,
165+ let tests = & [ ( Some ( range!( '(' , ; ')' ) ) , "'(,)'" . to_string( ) ) ,
166+ ( Some ( range!( '[' $low, ; ')' ) ) , format!( "'[{},)'" , $low_str) ) ,
167+ ( Some ( range!( '(' $low, ; ')' ) ) , format!( "'({},)'" , $low_str) ) ,
168+ ( Some ( range!( '(' , $high; ']' ) ) , format!( "'(,{}]'" , $high_str) ) ,
169+ ( Some ( range!( '(' , $high; ')' ) ) , format!( "'(,{})'" , $high_str) ) ,
170+ ( Some ( range!( '[' $low, $high; ']' ) ) ,
171171 format!( "'[{},{}]'" , $low_str, $high_str) ) ,
172- ( Some ( range!( '[' $low, $high ')' ) ) ,
172+ ( Some ( range!( '[' $low, $high; ')' ) ) ,
173173 format!( "'[{},{})'" , $low_str, $high_str) ) ,
174- ( Some ( range!( '(' $low, $high ']' ) ) ,
174+ ( Some ( range!( '(' $low, $high; ']' ) ) ,
175175 format!( "'({},{}]'" , $low_str, $high_str) ) ,
176- ( Some ( range!( '(' $low, $high ')' ) ) ,
176+ ( Some ( range!( '(' $low, $high; ')' ) ) ,
177177 format!( "'({},{})'" , $low_str, $high_str) ) ,
178178 ( Some ( range!( empty) ) , "'empty'" . to_string( ) ) ,
179179 ( None , "NULL" . to_string( ) ) ] ;
180180 test_type( $name, tests) ;
181181 } )
182182 }
183183
184- fn test_type < T : PartialEq +FromSql +ToSql , S : fmt:: Show > ( sql_type : & str , checks : & [ ( T , S ) ] ) {
184+ fn test_type < T : PartialEq +FromSql +ToSql , S : fmt:: String > ( sql_type : & str , checks : & [ ( T , S ) ] ) {
185185 let conn = Connection :: connect ( "postgres://postgres@localhost" , & SslMode :: None ) . unwrap ( ) ;
186186 for & ( ref val, ref repr) in checks. iter ( ) {
187187 let stmt = conn. prepare ( & * format ! ( "SELECT {}::{}" , * repr, sql_type) ) . unwrap ( ) ;
188- let result = stmt. query ( & [ ] ) . unwrap ( ) . next ( ) . unwrap ( ) . get ( 0 u ) ;
188+ let result = stmt. query ( & [ ] ) . unwrap ( ) . next ( ) . unwrap ( ) . get ( 0 ) ;
189189 assert ! ( val == & result) ;
190190
191191 let stmt = conn. prepare ( & * format ! ( "SELECT $1::{}" , sql_type) ) . unwrap ( ) ;
192- let result = stmt. query ( & [ val] ) . unwrap ( ) . next ( ) . unwrap ( ) . get ( 0 u ) ;
192+ let result = stmt. query ( & [ val] ) . unwrap ( ) . next ( ) . unwrap ( ) . get ( 0 ) ;
193193 assert ! ( val == & result) ;
194194 }
195195 }
0 commit comments