@@ -10,7 +10,7 @@ use postgres::types::{RawFromSql, ToSql, RawToSql, Type, Oid};
1010use { Array , ArrayBase , DimensionInfo } ;
1111
1212macro_rules! check_types {
13- ( $( $expected: pat) |+ , $actual : ident ) => (
13+ ( $actual : ident , $ ( $expected: pat) ,+ ) => (
1414 match $actual {
1515 $( & $expected) |+ => { }
1616 actual => return Err ( :: postgres:: Error :: WrongType ( actual. clone( ) ) )
@@ -19,10 +19,10 @@ macro_rules! check_types {
1919}
2020
2121macro_rules! from_sql_impl {
22- ( $( $oid: pat) |+ , $t : ty ) => {
22+ ( $t : ty , $ ( $oid: pat) ,+ ) => {
2323 impl :: postgres:: FromSql for Option <:: ArrayBase <Option <$t>>> {
2424 fn from_sql( ty: & :: postgres:: Type , raw: Option <& [ u8 ] >) -> :: postgres:: Result <Self > {
25- check_types!( $( $oid) |+ , ty ) ;
25+ check_types!( ty , $( $oid) ,+ ) ;
2626
2727 match raw {
2828 Some ( mut raw) => :: postgres:: types:: RawFromSql :: raw_from_sql( & mut raw) . map( Some ) ,
@@ -45,17 +45,17 @@ macro_rules! from_sql_impl {
4545}
4646
4747macro_rules! to_sql_impl {
48- ( $( $oid: pat) |+ , $t : ty ) => {
48+ ( $t : ty , $ ( $oid: pat) ,+ ) => {
4949 impl :: postgres:: ToSql for :: ArrayBase <Option <$t>> {
5050 fn to_sql( & self , ty: & :: postgres:: Type ) -> :: postgres:: Result <Option <Vec <u8 >>> {
51- check_types!( $( $oid) |+ , ty ) ;
51+ check_types!( ty , $( $oid) ,+ ) ;
5252 Ok ( Some ( :: impls:: raw_to_array( self , ty) ) )
5353 }
5454 }
5555
5656 impl :: postgres:: ToSql for Option <:: ArrayBase <Option <$t>>> {
5757 fn to_sql( & self , ty: & :: postgres:: Type ) -> :: postgres:: Result <Option <Vec <u8 >>> {
58- check_types!( $( $oid) |+ , ty ) ;
58+ check_types!( ty , $( $oid) ,+ ) ;
5959 match * self {
6060 Some ( ref arr) => arr. to_sql( ty) ,
6161 None => Ok ( None )
@@ -71,21 +71,21 @@ mod uuid;
7171
7272impl < T > RawFromSql for ArrayBase < Option < T > > where T : RawFromSql {
7373 fn raw_from_sql < R : Reader > ( raw : & mut R ) -> postgres:: Result < ArrayBase < Option < T > > > {
74- let ndim = try!( raw. read_be_u32 ( ) ) as uint ;
74+ let ndim = try!( raw. read_be_u32 ( ) ) as usize ;
7575 let _has_null = try!( raw. read_be_i32 ( ) ) == 1 ;
7676 let _element_type: Oid = try!( raw. read_be_u32 ( ) ) ;
7777
7878 let mut dim_info = Vec :: with_capacity ( ndim) ;
7979 for _ in range ( 0 , ndim) {
8080 dim_info. push ( DimensionInfo {
81- len : try!( raw. read_be_u32 ( ) ) as uint ,
82- lower_bound : try!( raw. read_be_i32 ( ) ) as int ,
81+ len : try!( raw. read_be_u32 ( ) ) as usize ,
82+ lower_bound : try!( raw. read_be_i32 ( ) ) as isize ,
8383 } ) ;
8484 }
8585 let nele = if dim_info. len ( ) == 0 {
8686 0
8787 } else {
88- dim_info. iter ( ) . map ( |info| info. len as uint ) . product ( )
88+ dim_info. iter ( ) . map ( |info| info. len as usize ) . product ( )
8989 } ;
9090
9191 let mut elements = Vec :: with_capacity ( nele) ;
@@ -94,7 +94,7 @@ impl<T> RawFromSql for ArrayBase<Option<T>> where T: RawFromSql {
9494 if len < 0 {
9595 elements. push ( None ) ;
9696 } else {
97- let mut limit = LimitReader :: new ( raw. by_ref ( ) , len as uint ) ;
97+ let mut limit = LimitReader :: new ( raw. by_ref ( ) , len as usize ) ;
9898 elements. push ( Some ( try!( RawFromSql :: raw_from_sql ( & mut limit) ) ) ) ;
9999 if limit. limit ( ) != 0 {
100100 return Err ( Error :: BadData ) ;
@@ -106,17 +106,17 @@ impl<T> RawFromSql for ArrayBase<Option<T>> where T: RawFromSql {
106106 }
107107}
108108
109- from_sql_impl ! ( Type :: BoolArray , bool ) ;
110- from_sql_impl ! ( Type :: ByteAArray , Vec <u8 >) ;
111- from_sql_impl ! ( Type :: CharArray , i8 ) ;
112- from_sql_impl ! ( Type :: Int2Array , i16 ) ;
113- from_sql_impl ! ( Type :: Int4Array , i32 ) ;
114- from_sql_impl ! ( Type :: TextArray | Type :: CharNArray | Type :: VarcharArray | Type :: NameArray , String ) ;
115- from_sql_impl ! ( Type :: Int8Array , i64 ) ;
116- from_sql_impl ! ( Type :: JsonArray , Json ) ;
117- from_sql_impl ! ( Type :: Float4Array , f32 ) ;
118- from_sql_impl ! ( Type :: Float8Array , f64 ) ;
119- from_sql_impl ! ( Type :: TimestampArray | Type :: TimestampTZArray , Timespec ) ;
109+ from_sql_impl ! ( bool , Type :: BoolArray ) ;
110+ from_sql_impl ! ( Vec <u8 >, Type :: ByteAArray ) ;
111+ from_sql_impl ! ( i8 , Type :: CharArray ) ;
112+ from_sql_impl ! ( i16 , Type :: Int2Array ) ;
113+ from_sql_impl ! ( i32 , Type :: Int4Array ) ;
114+ from_sql_impl ! ( String , Type :: TextArray , Type :: CharNArray , Type :: VarcharArray , Type :: NameArray ) ;
115+ from_sql_impl ! ( i64 , Type :: Int8Array ) ;
116+ from_sql_impl ! ( Json , Type :: JsonArray ) ;
117+ from_sql_impl ! ( f32 , Type :: Float4Array ) ;
118+ from_sql_impl ! ( f64 , Type :: Float8Array ) ;
119+ from_sql_impl ! ( Timespec , Type :: TimestampArray , Type :: TimestampTZArray ) ;
120120
121121fn raw_to_array < T > ( array : & ArrayBase < Option < T > > , ty : & Type ) -> Vec < u8 > where T : RawToSql {
122122 let mut buf = vec ! [ ] ;
@@ -147,17 +147,17 @@ fn raw_to_array<T>(array: &ArrayBase<Option<T>>, ty: &Type) -> Vec<u8> where T:
147147 buf
148148}
149149
150- to_sql_impl ! ( Type :: BoolArray , bool ) ;
151- to_sql_impl ! ( Type :: ByteAArray , Vec <u8 >) ;
152- to_sql_impl ! ( Type :: CharArray , i8 ) ;
153- to_sql_impl ! ( Type :: Int2Array , i16 ) ;
154- to_sql_impl ! ( Type :: Int4Array , i32 ) ;
155- to_sql_impl ! ( Type :: Int8Array , i64 ) ;
156- to_sql_impl ! ( Type :: TextArray | Type :: CharNArray | Type :: VarcharArray | Type :: NameArray , String ) ;
157- to_sql_impl ! ( Type :: Float4Array , f32 ) ;
158- to_sql_impl ! ( Type :: Float8Array , f64 ) ;
159- to_sql_impl ! ( Type :: JsonArray , Json ) ;
160- to_sql_impl ! ( Type :: TimestampArray | Type :: TimestampTZArray , Timespec ) ;
150+ to_sql_impl ! ( bool , Type :: BoolArray ) ;
151+ to_sql_impl ! ( Vec <u8 >, Type :: ByteAArray ) ;
152+ to_sql_impl ! ( i8 , Type :: CharArray ) ;
153+ to_sql_impl ! ( i16 , Type :: Int2Array ) ;
154+ to_sql_impl ! ( i32 , Type :: Int4Array ) ;
155+ to_sql_impl ! ( i64 , Type :: Int8Array ) ;
156+ to_sql_impl ! ( String , Type :: TextArray , Type :: CharNArray , Type :: VarcharArray , Type :: NameArray ) ;
157+ to_sql_impl ! ( f32 , Type :: Float4Array ) ;
158+ to_sql_impl ! ( f64 , Type :: Float8Array ) ;
159+ to_sql_impl ! ( Json , Type :: JsonArray ) ;
160+ to_sql_impl ! ( Timespec , Type :: TimestampArray , Type :: TimestampTZArray ) ;
161161
162162#[ cfg( test) ]
163163mod test {
@@ -166,15 +166,15 @@ mod test {
166166 use postgres:: { Connection , SslMode , FromSql , ToSql } ;
167167 use ArrayBase ;
168168
169- fn test_type < T : PartialEq +FromSql +ToSql , S : fmt:: Show > ( sql_type : & str , checks : & [ ( T , S ) ] ) {
169+ fn test_type < T : PartialEq +FromSql +ToSql , S : fmt:: String > ( sql_type : & str , checks : & [ ( T , S ) ] ) {
170170 let conn = Connection :: connect ( "postgres://postgres@localhost" , & SslMode :: None ) . unwrap ( ) ;
171171 for & ( ref val, ref repr) in checks. iter ( ) {
172- let stmt = conn. prepare ( format ! ( "SELECT {}::{}" , * repr, sql_type) [ ] ) . unwrap ( ) ;
173- let result = stmt. query ( & [ ] ) . unwrap ( ) . next ( ) . unwrap ( ) . get ( 0 u ) ;
172+ let stmt = conn. prepare ( & format ! ( "SELECT {}::{}" , * repr, sql_type) [ ] ) . unwrap ( ) ;
173+ let result = stmt. query ( & [ ] ) . unwrap ( ) . next ( ) . unwrap ( ) . get ( 0 ) ;
174174 assert ! ( val == & result) ;
175175
176- let stmt = conn. prepare ( format ! ( "SELECT $1::{}" , sql_type) [ ] ) . unwrap ( ) ;
177- let result = stmt. query ( & [ val] ) . unwrap ( ) . next ( ) . unwrap ( ) . get ( 0 u ) ;
176+ let stmt = conn. prepare ( & format ! ( "SELECT $1::{}" , sql_type) [ ] ) . unwrap ( ) ;
177+ let result = stmt. query ( & [ val] ) . unwrap ( ) . next ( ) . unwrap ( ) . get ( 0 ) ;
178178 assert ! ( val == & result) ;
179179 }
180180 }
@@ -183,15 +183,15 @@ mod test {
183183 ( $name: expr, $v1: expr, $s1: expr, $v2: expr, $s2: expr, $v3: expr, $s3: expr) => ( {
184184
185185 let tests = & [ ( Some ( ArrayBase :: from_vec( vec!( Some ( $v1) , Some ( $v2) , None ) , 1 ) ) ,
186- format!( "'{{{},{},NULL}}'" , $s1, $s2) . into_string ( ) ) ,
186+ format!( "'{{{},{},NULL}}'" , $s1, $s2) ) ,
187187 ( None , "NULL" . to_string( ) ) ] ;
188- test_type( format!( "{}[]" , $name) [ ] , tests) ;
188+ test_type( & format!( "{}[]" , $name) [ ] , tests) ;
189189 let mut a = ArrayBase :: from_vec( vec!( Some ( $v1) , Some ( $v2) ) , 0 ) ;
190190 a. wrap( -1 ) ;
191191 a. push_move( ArrayBase :: from_vec( vec!( None , Some ( $v3) ) , 0 ) ) ;
192192 let tests = & [ ( Some ( a) , format!( "'[-1:0][0:1]={{{{{},{}}},{{NULL,{}}}}}'" ,
193- $s1, $s2, $s3) . into_string ( ) ) ] ;
194- test_type( format!( "{}[][]" , $name) [ ] , tests) ;
193+ $s1, $s2, $s3) ) ] ;
194+ test_type( & format!( "{}[][]" , $name) [ ] , tests) ;
195195 } )
196196 }
197197
0 commit comments