11//! Traits dealing with Postgres data types
22use serialize:: json;
33use std:: collections:: HashMap ;
4- use std:: io:: ByRefReader ;
5- use std:: io:: util:: LimitReader ;
64use std:: io:: net:: ip:: IpAddr ;
75
86use Result ;
97use error:: Error ;
10- use types:: range:: { Range , RangeBound , BoundSided , BoundType , Normalizable } ;
118
129macro_rules! check_types {
1310 ( $( $expected: pat) |+, $actual: ident) => (
@@ -133,7 +130,6 @@ macro_rules! to_raw_to_impl {
133130 )
134131}
135132
136- pub mod range;
137133#[ cfg( feature = "uuid" ) ]
138134mod uuid;
139135mod time;
@@ -188,12 +184,6 @@ const TSTZRANGEARRAYOID: Oid = 3911;
188184const INT8RANGEOID : Oid = 3926 ;
189185const INT8RANGEARRAYOID : Oid = 3927 ;
190186
191- const RANGE_UPPER_UNBOUNDED : i8 = 0b0001_0000 ;
192- const RANGE_LOWER_UNBOUNDED : i8 = 0b0000_1000 ;
193- const RANGE_UPPER_INCLUSIVE : i8 = 0b0000_0100 ;
194- const RANGE_LOWER_INCLUSIVE : i8 = 0b0000_0010 ;
195- const RANGE_EMPTY : i8 = 0b0000_0001 ;
196-
197187macro_rules! make_postgres_type {
198188 ( $( #[ $doc: meta] $oid: ident => $variant: ident $( member $member: ident) * ) ,+) => (
199189 /// A Postgres type
@@ -417,41 +407,6 @@ impl RawFromSql for IpAddr {
417407 }
418408}
419409
420- impl < T > RawFromSql for Range < T > where T : PartialOrd +Normalizable +RawFromSql {
421- fn raw_from_sql < R : Reader > ( rdr : & mut R ) -> Result < Range < T > > {
422- let t = try!( rdr. read_i8 ( ) ) ;
423-
424- if t & RANGE_EMPTY != 0 {
425- return Ok ( Range :: empty ( ) ) ;
426- }
427-
428- fn make_bound < S , T , R > ( rdr : & mut R , tag : i8 , bound_flag : i8 , inclusive_flag : i8 )
429- -> Result < Option < RangeBound < S , T > > >
430- where S : BoundSided , T : PartialOrd +Normalizable +RawFromSql , R : Reader {
431- match tag & bound_flag {
432- 0 => {
433- let type_ = match tag & inclusive_flag {
434- 0 => BoundType :: Exclusive ,
435- _ => BoundType :: Inclusive ,
436- } ;
437- let len = try!( rdr. read_be_i32 ( ) ) as uint ;
438- let mut limit = LimitReader :: new ( rdr. by_ref ( ) , len) ;
439- let bound = try!( RawFromSql :: raw_from_sql ( & mut limit) ) ;
440- if limit. limit ( ) != 0 {
441- return Err ( Error :: BadData ) ;
442- }
443- Ok ( Some ( RangeBound :: new ( bound, type_) ) )
444- }
445- _ => Ok ( None )
446- }
447- }
448-
449- let lower = try!( make_bound ( rdr, t, RANGE_LOWER_UNBOUNDED , RANGE_LOWER_INCLUSIVE ) ) ;
450- let upper = try!( make_bound ( rdr, t, RANGE_UPPER_UNBOUNDED , RANGE_UPPER_INCLUSIVE ) ) ;
451- Ok ( Range :: new ( lower, upper) )
452- }
453- }
454-
455410from_raw_from_impl ! ( Type :: Bool , bool ) ;
456411from_raw_from_impl ! ( Type :: ByteA , Vec <u8 >) ;
457412from_raw_from_impl ! ( Type :: Char , i8 ) ;
@@ -464,9 +419,6 @@ from_raw_from_impl!(Type::Float8, f64);
464419from_raw_from_impl ! ( Type :: Json , json:: Json ) ;
465420from_raw_from_impl ! ( Type :: Inet | Type :: Cidr , IpAddr ) ;
466421
467- from_raw_from_impl ! ( Type :: Int4Range , Range <i32 >) ;
468- from_raw_from_impl ! ( Type :: Int8Range , Range <i64 >) ;
469-
470422impl FromSql for Option < String > {
471423 fn from_sql ( ty : & Type , raw : Option < & [ u8 ] > ) -> Result < Option < String > > {
472424 match * ty {
@@ -608,44 +560,6 @@ impl RawToSql for IpAddr {
608560 }
609561}
610562
611- impl < T > RawToSql for Range < T > where T : PartialOrd +Normalizable +RawToSql {
612- fn raw_to_sql < W : Writer > ( & self , buf : & mut W ) -> Result < ( ) > {
613- let mut tag = 0 ;
614- if self . is_empty ( ) {
615- tag |= RANGE_EMPTY ;
616- } else {
617- fn make_tag < S , T > ( bound : Option < & RangeBound < S , T > > , unbounded_tag : i8 ,
618- inclusive_tag : i8 ) -> i8 where S : BoundSided {
619- match bound {
620- None => unbounded_tag,
621- Some ( & RangeBound { type_ : BoundType :: Inclusive , .. } ) => inclusive_tag,
622- _ => 0
623- }
624- }
625- tag |= make_tag ( self . lower ( ) , RANGE_LOWER_UNBOUNDED , RANGE_LOWER_INCLUSIVE ) ;
626- tag |= make_tag ( self . upper ( ) , RANGE_UPPER_UNBOUNDED , RANGE_UPPER_INCLUSIVE ) ;
627- }
628-
629- try!( buf. write_i8 ( tag) ) ;
630-
631- fn write_value < S , T , W > ( buf : & mut W , v : Option < & RangeBound < S , T > > ) -> Result < ( ) >
632- where S : BoundSided , T : RawToSql , W : Writer {
633- if let Some ( bound) = v {
634- let mut inner_buf = vec ! [ ] ;
635- try!( bound. value . raw_to_sql ( & mut inner_buf) ) ;
636- try!( buf. write_be_u32 ( inner_buf. len ( ) as u32 ) ) ;
637- try!( buf. write ( & * inner_buf) ) ;
638- }
639- Ok ( ( ) )
640- }
641-
642- try!( write_value ( buf, self . lower ( ) ) ) ;
643- try!( write_value ( buf, self . upper ( ) ) ) ;
644-
645- Ok ( ( ) )
646- }
647- }
648-
649563to_raw_to_impl ! ( Type :: Bool , bool ) ;
650564to_raw_to_impl ! ( Type :: ByteA , Vec <u8 >) ;
651565to_raw_to_impl ! ( Type :: Json , json:: Json ) ;
@@ -657,8 +571,6 @@ to_raw_to_impl!(Type::Oid, u32);
657571to_raw_to_impl ! ( Type :: Int8 , i64 ) ;
658572to_raw_to_impl ! ( Type :: Float4 , f32 ) ;
659573to_raw_to_impl ! ( Type :: Float8 , f64 ) ;
660- to_raw_to_impl ! ( Type :: Int4Range , Range <i32 >) ;
661- to_raw_to_impl ! ( Type :: Int8Range , Range <i64 >) ;
662574
663575impl ToSql for String {
664576 fn to_sql ( & self , ty : & Type ) -> Result < Option < Vec < u8 > > > {
0 commit comments