Partial update

This commit is contained in:
Steven Fackler 2015-01-09 10:26:24 -08:00
parent c27dcd86b5
commit 4f157bb4a8
5 changed files with 90 additions and 106 deletions

View File

@ -406,7 +406,7 @@ impl InnerConnection {
let mut conn = InnerConnection { let mut conn = InnerConnection {
stream: BufferedStream::new(stream), stream: BufferedStream::new(stream),
next_stmt_id: 0, next_stmt_id: 0,
notice_handler: box DefaultNoticeHandler, notice_handler: Box::new(DefaultNoticeHandler),
notifications: RingBuf::new(), notifications: RingBuf::new(),
cancel_data: CancelData { process_id: 0, secret_key: 0 }, cancel_data: CancelData { process_id: 0, secret_key: 0 },
unknown_types: HashMap::new(), unknown_types: HashMap::new(),

View File

@ -7,7 +7,7 @@ use Result;
use error::Error; use error::Error;
macro_rules! check_types { macro_rules! check_types {
($($expected:pat)|+, $actual:ident) => ( ($($expected:pat),+; $actual:ident) => (
match $actual { match $actual {
$(&$expected)|+ => {} $(&$expected)|+ => {}
actual => return Err(::Error::WrongType(actual.clone())) actual => return Err(::Error::WrongType(actual.clone()))
@ -26,8 +26,7 @@ macro_rules! raw_from_impl {
} }
macro_rules! from_option_impl { macro_rules! from_option_impl {
($t:ty $(, $a:meta)*) => { ($t:ty) => {
$(#[$a])*
impl ::types::FromSql for $t { impl ::types::FromSql for $t {
fn from_sql(ty: &Type, raw: Option<&[u8]>) -> Result<$t> { fn from_sql(ty: &Type, raw: Option<&[u8]>) -> Result<$t> {
use Error; use Error;
@ -46,11 +45,10 @@ macro_rules! from_option_impl {
} }
macro_rules! from_map_impl { macro_rules! from_map_impl {
($($expected:pat)|+, $t:ty, $blk:expr $(, $a:meta)*) => ( ($($expected:pat),+; $t:ty, $blk:expr) => (
$(#[$a])*
impl ::types::FromSql for Option<$t> { impl ::types::FromSql for Option<$t> {
fn from_sql(ty: &Type, raw: Option<&[u8]>) -> Result<Option<$t>> { fn from_sql(ty: &Type, raw: Option<&[u8]>) -> Result<Option<$t>> {
check_types!($($expected)|+, ty); check_types!($($expected),+; ty);
match raw { match raw {
Some(buf) => ($blk)(buf).map(|ok| Some(ok)), Some(buf) => ($blk)(buf).map(|ok| Some(ok)),
None => Ok(None) None => Ok(None)
@ -58,17 +56,17 @@ macro_rules! from_map_impl {
} }
} }
from_option_impl!($t $(, $a)*); from_option_impl!($t);
) )
} }
macro_rules! from_raw_from_impl { macro_rules! from_raw_from_impl {
($($expected:pat)|+, $t:ty $(, $a:meta)*) => ( ($($expected:pat),+; $t:ty) => (
from_map_impl!($($expected)|+, $t, |&mut: mut buf: &[u8]| { from_map_impl!($($expected),+; $t, |&mut: mut buf: &[u8]| {
use types::RawFromSql; use types::RawFromSql;
RawFromSql::raw_from_sql(&mut buf) RawFromSql::raw_from_sql(&mut buf)
} $(, $a)*); });
) )
} }
@ -83,11 +81,10 @@ macro_rules! raw_to_impl {
} }
macro_rules! to_option_impl { macro_rules! to_option_impl {
($($oid:pat)|+, $t:ty $(,$a:meta)*) => ( ($($oid:pat),+; $t:ty) => (
$(#[$a])*
impl ::types::ToSql for Option<$t> { impl ::types::ToSql for Option<$t> {
fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> { fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> {
check_types!($($oid)|+, ty); check_types!($($oid),+; ty);
match *self { match *self {
None => Ok(None), None => Ok(None),
@ -99,10 +96,10 @@ macro_rules! to_option_impl {
} }
macro_rules! to_option_impl_lifetime { macro_rules! to_option_impl_lifetime {
($($oid:pat)|+, $t:ty) => ( ($($oid:pat),+; $t:ty) => (
impl<'a> ToSql for Option<$t> { impl<'a> ToSql for Option<$t> {
fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> { fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> {
check_types!($($oid)|+, ty); check_types!($($oid),+; ty);
match *self { match *self {
None => Ok(None), None => Ok(None),
@ -114,11 +111,10 @@ macro_rules! to_option_impl_lifetime {
} }
macro_rules! to_raw_to_impl { macro_rules! to_raw_to_impl {
($($oid:pat)|+, $t:ty $(, $a:meta)*) => ( ($($oid:pat),+; $t:ty) => (
$(#[$a])*
impl ::types::ToSql for $t { impl ::types::ToSql for $t {
fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> { fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> {
check_types!($($oid)|+, ty); check_types!($($oid),+; ty);
let mut writer = vec![]; let mut writer = vec![];
try!(self.raw_to_sql(&mut writer)); try!(self.raw_to_sql(&mut writer));
@ -126,7 +122,7 @@ macro_rules! to_raw_to_impl {
} }
} }
to_option_impl!($($oid)|+, $t $(, $a)*); to_option_impl!($($oid),+; $t);
) )
} }
@ -185,7 +181,7 @@ const INT8RANGEOID: Oid = 3926;
const INT8RANGEARRAYOID: Oid = 3927; const INT8RANGEARRAYOID: Oid = 3927;
macro_rules! make_postgres_type { macro_rules! make_postgres_type {
($(#[$doc:meta] $oid:ident => $variant:ident $(member $member:ident)*),+) => ( ($(#[$doc:meta] $oid:ident => $variant:ident: $(member $member:ident)*),+) => (
/// A Postgres type /// A Postgres type
#[derive(PartialEq, Eq, Clone, Show)] #[derive(PartialEq, Eq, Clone, Show)]
pub enum Type { pub enum Type {
@ -242,95 +238,95 @@ macro_rules! make_postgres_type {
make_postgres_type! { make_postgres_type! {
#[doc="BOOL"] #[doc="BOOL"]
BOOLOID => Bool, BOOLOID => Bool:,
#[doc="BYTEA"] #[doc="BYTEA"]
BYTEAOID => ByteA, BYTEAOID => ByteA:,
#[doc="\"char\""] #[doc="\"char\""]
CHAROID => Char, CHAROID => Char:,
#[doc="NAME"] #[doc="NAME"]
NAMEOID => Name, NAMEOID => Name:,
#[doc="INT8/BIGINT"] #[doc="INT8/BIGINT"]
INT8OID => Int8, INT8OID => Int8:,
#[doc="INT2/SMALLINT"] #[doc="INT2/SMALLINT"]
INT2OID => Int2, INT2OID => Int2:,
#[doc="INT4/INT"] #[doc="INT4/INT"]
INT4OID => Int4, INT4OID => Int4:,
#[doc="TEXT"] #[doc="TEXT"]
TEXTOID => Text, TEXTOID => Text:,
#[doc="OID"] #[doc="OID"]
OIDOID => Oid, OIDOID => Oid:,
#[doc="JSON"] #[doc="JSON"]
JSONOID => Json, JSONOID => Json:,
#[doc="CIDR"] #[doc="CIDR"]
CIDROID => Cidr, CIDROID => Cidr:,
#[doc="JSON[]"] #[doc="JSON[]"]
JSONARRAYOID => JsonArray member Json, JSONARRAYOID => JsonArray: member Json,
#[doc="FLOAT4/REAL"] #[doc="FLOAT4/REAL"]
FLOAT4OID => Float4, FLOAT4OID => Float4:,
#[doc="FLOAT8/DOUBLE PRECISION"] #[doc="FLOAT8/DOUBLE PRECISION"]
FLOAT8OID => Float8, FLOAT8OID => Float8:,
#[doc="INET"] #[doc="INET"]
INETOID => Inet, INETOID => Inet:,
#[doc="BOOL[]"] #[doc="BOOL[]"]
BOOLARRAYOID => BoolArray member Bool, BOOLARRAYOID => BoolArray: member Bool,
#[doc="BYTEA[]"] #[doc="BYTEA[]"]
BYTEAARRAYOID => ByteAArray member ByteA, BYTEAARRAYOID => ByteAArray: member ByteA,
#[doc="\"char\"[]"] #[doc="\"char\"[]"]
CHARARRAYOID => CharArray member Char, CHARARRAYOID => CharArray: member Char,
#[doc="NAME[]"] #[doc="NAME[]"]
NAMEARRAYOID => NameArray member Name, NAMEARRAYOID => NameArray: member Name,
#[doc="INT2[]"] #[doc="INT2[]"]
INT2ARRAYOID => Int2Array member Int2, INT2ARRAYOID => Int2Array: member Int2,
#[doc="INT4[]"] #[doc="INT4[]"]
INT4ARRAYOID => Int4Array member Int4, INT4ARRAYOID => Int4Array: member Int4,
#[doc="TEXT[]"] #[doc="TEXT[]"]
TEXTARRAYOID => TextArray member Text, TEXTARRAYOID => TextArray: member Text,
#[doc="CHAR(n)[]"] #[doc="CHAR(n)[]"]
BPCHARARRAYOID => CharNArray member CharN, BPCHARARRAYOID => CharNArray: member CharN,
#[doc="VARCHAR[]"] #[doc="VARCHAR[]"]
VARCHARARRAYOID => VarcharArray member Varchar, VARCHARARRAYOID => VarcharArray: member Varchar,
#[doc="INT8[]"] #[doc="INT8[]"]
INT8ARRAYOID => Int8Array member Int8, INT8ARRAYOID => Int8Array: member Int8,
#[doc="FLOAT4[]"] #[doc="FLOAT4[]"]
FLOAT4ARRAYOID => Float4Array member Float4, FLOAT4ARRAYOID => Float4Array: member Float4,
#[doc="FLOAT8[]"] #[doc="FLOAT8[]"]
FLAOT8ARRAYOID => Float8Array member Float8, FLAOT8ARRAYOID => Float8Array: member Float8,
#[doc="TIMESTAMP"] #[doc="TIMESTAMP"]
TIMESTAMPOID => Timestamp, TIMESTAMPOID => Timestamp:,
#[doc="TIMESTAMP[]"] #[doc="TIMESTAMP[]"]
TIMESTAMPARRAYOID => TimestampArray member Timestamp, TIMESTAMPARRAYOID => TimestampArray: member Timestamp,
#[doc="TIMESTAMP WITH TIME ZONE"] #[doc="TIMESTAMP WITH TIME ZONE"]
TIMESTAMPZOID => TimestampTZ, TIMESTAMPZOID => TimestampTZ:,
#[doc="TIMESTAMP WITH TIME ZONE[]"] #[doc="TIMESTAMP WITH TIME ZONE[]"]
TIMESTAMPZARRAYOID => TimestampTZArray member TimestampTZ, TIMESTAMPZARRAYOID => TimestampTZArray: member TimestampTZ,
#[doc="UUID"] #[doc="UUID"]
UUIDOID => Uuid, UUIDOID => Uuid:,
#[doc="UUID[]"] #[doc="UUID[]"]
UUIDARRAYOID => UuidArray member Uuid, UUIDARRAYOID => UuidArray: member Uuid,
#[doc="JSONB"] #[doc="JSONB"]
JSONBOID => Jsonb, JSONBOID => Jsonb:,
#[doc="JSONB[]"] #[doc="JSONB[]"]
JSONBARRAYOID => JsonbArray member Jsonb, JSONBARRAYOID => JsonbArray: member Jsonb,
#[doc="CHAR(n)/CHARACTER(n)"] #[doc="CHAR(n)/CHARACTER(n)"]
BPCHAROID => CharN, BPCHAROID => CharN:,
#[doc="VARCHAR/CHARACTER VARYING"] #[doc="VARCHAR/CHARACTER VARYING"]
VARCHAROID => Varchar, VARCHAROID => Varchar:,
#[doc="INT4RANGE"] #[doc="INT4RANGE"]
INT4RANGEOID => Int4Range, INT4RANGEOID => Int4Range:,
#[doc="INT4RANGE[]"] #[doc="INT4RANGE[]"]
INT4RANGEARRAYOID => Int4RangeArray member Int4Range, INT4RANGEARRAYOID => Int4RangeArray: member Int4Range,
#[doc="TSRANGE"] #[doc="TSRANGE"]
TSRANGEOID => TsRange, TSRANGEOID => TsRange:,
#[doc="TSRANGE[]"] #[doc="TSRANGE[]"]
TSRANGEARRAYOID => TsRangeArray member TsRange, TSRANGEARRAYOID => TsRangeArray: member TsRange,
#[doc="TSTZRANGE"] #[doc="TSTZRANGE"]
TSTZRANGEOID => TstzRange, TSTZRANGEOID => TstzRange:,
#[doc="TSTZRANGE[]"] #[doc="TSTZRANGE[]"]
TSTZRANGEARRAYOID => TstzRangeArray member TstzRange, TSTZRANGEARRAYOID => TstzRangeArray: member TstzRange,
#[doc="INT8RANGE"] #[doc="INT8RANGE"]
INT8RANGEOID => Int8Range, INT8RANGEOID => Int8Range:,
#[doc="INT8RANGE[]"] #[doc="INT8RANGE[]"]
INT8RANGEARRAYOID => Int8RangeArray member Int8Range INT8RANGEARRAYOID => Int8RangeArray: member Int8Range
} }
/// A trait for types that can be created from a Postgres value /// A trait for types that can be created from a Postgres value
@ -407,17 +403,17 @@ impl RawFromSql for IpAddr {
} }
} }
from_raw_from_impl!(Type::Bool, bool); from_raw_from_impl!(Type::Bool; bool);
from_raw_from_impl!(Type::ByteA, Vec<u8>); from_raw_from_impl!(Type::ByteA; Vec<u8>);
from_raw_from_impl!(Type::Char, i8); from_raw_from_impl!(Type::Char; i8);
from_raw_from_impl!(Type::Int2, i16); from_raw_from_impl!(Type::Int2; i16);
from_raw_from_impl!(Type::Int4, i32); from_raw_from_impl!(Type::Int4; i32);
from_raw_from_impl!(Type::Oid, u32); from_raw_from_impl!(Type::Oid; u32);
from_raw_from_impl!(Type::Int8, i64); from_raw_from_impl!(Type::Int8; i64);
from_raw_from_impl!(Type::Float4, f32); from_raw_from_impl!(Type::Float4; f32);
from_raw_from_impl!(Type::Float8, f64); from_raw_from_impl!(Type::Float8; f64);
from_raw_from_impl!(Type::Json, json::Json); from_raw_from_impl!(Type::Json; json::Json);
from_raw_from_impl!(Type::Inet | Type::Cidr, IpAddr); from_raw_from_impl!(Type::Inet, Type::Cidr; IpAddr);
impl FromSql for Option<String> { impl FromSql for Option<String> {
fn from_sql(ty: &Type, raw: Option<&[u8]>) -> Result<Option<String>> { fn from_sql(ty: &Type, raw: Option<&[u8]>) -> Result<Option<String>> {
@ -560,17 +556,17 @@ impl RawToSql for IpAddr {
} }
} }
to_raw_to_impl!(Type::Bool, bool); to_raw_to_impl!(Type::Bool; bool);
to_raw_to_impl!(Type::ByteA, Vec<u8>); to_raw_to_impl!(Type::ByteA; Vec<u8>);
to_raw_to_impl!(Type::Json, json::Json); to_raw_to_impl!(Type::Json; json::Json);
to_raw_to_impl!(Type::Inet | Type::Cidr, IpAddr); to_raw_to_impl!(Type::Inet, Type::Cidr; IpAddr);
to_raw_to_impl!(Type::Char, i8); to_raw_to_impl!(Type::Char; i8);
to_raw_to_impl!(Type::Int2, i16); to_raw_to_impl!(Type::Int2; i16);
to_raw_to_impl!(Type::Int4, i32); to_raw_to_impl!(Type::Int4; i32);
to_raw_to_impl!(Type::Oid, u32); to_raw_to_impl!(Type::Oid; u32);
to_raw_to_impl!(Type::Int8, i64); to_raw_to_impl!(Type::Int8; i64);
to_raw_to_impl!(Type::Float4, f32); to_raw_to_impl!(Type::Float4; f32);
to_raw_to_impl!(Type::Float8, f64); to_raw_to_impl!(Type::Float8; f64);
impl ToSql for String { impl ToSql for String {
fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> { fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> {
@ -611,12 +607,12 @@ impl<'a> ToSql for Option<&'a str> {
impl<'a> ToSql for &'a [u8] { impl<'a> ToSql for &'a [u8] {
fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> { fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> {
check_types!(Type::ByteA, ty); check_types!(Type::ByteA; ty);
Ok(Some(self.to_vec())) Ok(Some(self.to_vec()))
} }
} }
to_option_impl_lifetime!(Type::ByteA, &'a [u8]); to_option_impl_lifetime!(Type::ByteA; &'a [u8]);
impl ToSql for HashMap<String, Option<String>> { impl ToSql for HashMap<String, Option<String>> {
fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> { fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> {

View File

@ -23,7 +23,7 @@ impl RawFromSql for Timespec {
} }
} }
from_raw_from_impl!(Type::Timestamp | Type::TimestampTZ, Timespec); from_raw_from_impl!(Type::Timestamp, Type::TimestampTZ; Timespec);
impl RawToSql for Timespec { impl RawToSql for Timespec {
fn raw_to_sql<W: Writer>(&self, w: &mut W) -> Result<()> { fn raw_to_sql<W: Writer>(&self, w: &mut W) -> Result<()> {
@ -32,5 +32,5 @@ impl RawToSql for Timespec {
} }
} }
to_raw_to_impl!(Type::Timestamp | Type::TimestampTZ, Timespec); to_raw_to_impl!(Type::Timestamp, Type::TimestampTZ; Timespec);

View File

@ -14,7 +14,7 @@ impl RawFromSql for Uuid {
} }
} }
from_raw_from_impl!(Type::Uuid, Uuid, doc = "requires the \"uuid\" feature"); from_raw_from_impl!(Type::Uuid; Uuid);
impl RawToSql for Uuid { impl RawToSql for Uuid {
fn raw_to_sql<W: Writer>(&self, w: &mut W) -> Result<()> { fn raw_to_sql<W: Writer>(&self, w: &mut W) -> Result<()> {
@ -22,4 +22,4 @@ impl RawToSql for Uuid {
} }
} }
to_raw_to_impl!(Type::Uuid, Uuid, doc = "requires the \"uuid\" feature"); to_raw_to_impl!(Type::Uuid; Uuid);

View File

@ -518,15 +518,3 @@ impl fmt::Show for Path {
} }
} }
impl<S: hash::Writer> hash::Hash<S> for Url {
fn hash(&self, state: &mut S) {
self.to_string().hash(state)
}
}
impl<S: hash::Writer> hash::Hash<S> for Path {
fn hash(&self, state: &mut S) {
self.to_string().hash(state)
}
}