diff --git a/codegen/src/main.rs b/codegen/src/main.rs index 293686cb..7ca96fe9 100644 --- a/codegen/src/main.rs +++ b/codegen/src/main.rs @@ -9,7 +9,7 @@ mod sqlstate; mod type_gen; fn main() { - let path = Path::new(".."); + let path = Path::new("../postgres-shared/src"); sqlstate::build(path); type_gen::build(path); } diff --git a/codegen/src/sqlstate.rs b/codegen/src/sqlstate.rs index 94f37ae0..03bffaf9 100644 --- a/codegen/src/sqlstate.rs +++ b/codegen/src/sqlstate.rs @@ -13,7 +13,7 @@ struct Code { } pub fn build(path: &Path) { - let mut file = BufWriter::new(File::create(path.join("postgres-shared/src/error/sqlstate.rs")).unwrap()); + let mut file = BufWriter::new(File::create(path.join("error/sqlstate.rs")).unwrap()); let codes = parse_codes(); diff --git a/codegen/src/type_gen.rs b/codegen/src/type_gen.rs index 034b4e3a..49607538 100644 --- a/codegen/src/type_gen.rs +++ b/codegen/src/type_gen.rs @@ -20,7 +20,7 @@ struct Type { } pub fn build(path: &Path) { - let mut file = BufWriter::new(File::create(path.join("postgres/src/types/type_gen.rs")).unwrap()); + let mut file = BufWriter::new(File::create(path.join("types/type_gen.rs")).unwrap()); let ranges = parse_ranges(); let types = parse_types(&ranges); diff --git a/postgres-shared/Cargo.toml b/postgres-shared/Cargo.toml index 8c433c73..a14d4ce5 100644 --- a/postgres-shared/Cargo.toml +++ b/postgres-shared/Cargo.toml @@ -3,8 +3,23 @@ name = "postgres-shared" version = "0.1.0" authors = ["Steven Fackler "] +[features] +with-bit-vec = ["bit-vec"] +with-chrono = ["chrono"] +with-eui48 = ["eui48"] +with-serde_json = ["serde_json"] +with-time = ["time"] +with-uuid = ["uuid"] + [dependencies] hex = "0.2" fallible-iterator = "0.1.3" phf = "=0.7.20" postgres-protocol = "0.2" + +bit-vec = { version = "0.4", optional = true } +chrono = { version = "0.2.14", optional = true } +eui48 = { version = "0.1", optional = true } +serde_json = { version = ">= 0.6, < 0.9", optional = true } +time = { version = "0.1.14", optional = true } +uuid = { version = ">= 0.1, < 0.4", optional = true } diff --git a/postgres-shared/src/lib.rs b/postgres-shared/src/lib.rs index 9ce1f019..cdde9268 100644 --- a/postgres-shared/src/lib.rs +++ b/postgres-shared/src/lib.rs @@ -10,6 +10,7 @@ use std::ops::Range; pub mod error; pub mod params; +pub mod types; pub struct RowData { buf: Vec, diff --git a/postgres/src/types/bit_vec.rs b/postgres-shared/src/types/bit_vec.rs similarity index 100% rename from postgres/src/types/bit_vec.rs rename to postgres-shared/src/types/bit_vec.rs diff --git a/postgres/src/types/chrono.rs b/postgres-shared/src/types/chrono.rs similarity index 100% rename from postgres/src/types/chrono.rs rename to postgres-shared/src/types/chrono.rs diff --git a/postgres/src/types/eui48.rs b/postgres-shared/src/types/eui48.rs similarity index 100% rename from postgres/src/types/eui48.rs rename to postgres-shared/src/types/eui48.rs diff --git a/postgres/src/types/mod.rs b/postgres-shared/src/types/mod.rs similarity index 98% rename from postgres/src/types/mod.rs rename to postgres-shared/src/types/mod.rs index cb812cb7..edb57ee3 100644 --- a/postgres/src/types/mod.rs +++ b/postgres-shared/src/types/mod.rs @@ -1,5 +1,3 @@ -//! Traits dealing with Postgres data types - use fallible_iterator::FallibleIterator; use postgres_protocol; use postgres_protocol::types::{self, ArrayDimension}; @@ -13,7 +11,6 @@ pub use postgres_protocol::Oid; pub use self::type_gen::Type; pub use self::special::{Date, Timestamp}; -use {SessionInfoNew, OtherNew, WrongTypeNew, FieldNew}; /// Generates a simple implementation of `ToSql::accepts` which accepts the /// types passed to it. @@ -88,8 +85,9 @@ pub struct SessionInfo<'a> { parameters: &'a HashMap, } -impl<'a> SessionInfoNew<'a> for SessionInfo<'a> { - fn new(parameters: &'a HashMap) -> SessionInfo<'a> { +impl<'a> SessionInfo<'a> { + #[doc(hidden)] + pub fn new(parameters: &'a HashMap) -> SessionInfo<'a> { SessionInfo { parameters: parameters } } } @@ -142,8 +140,9 @@ impl Field { } } -impl FieldNew for Field { - fn new(name: String, type_: Type) -> Field { +impl Field { + #[doc(hidden)] + pub fn new(name: String, type_: Type) -> Field { Field { name: name, type_: type_, @@ -174,8 +173,9 @@ struct OtherInner { schema: String, } -impl OtherNew for Other { - fn new(name: String, oid: Oid, kind: Kind, schema: String) -> Other { +impl Other { + #[doc(hidden)] + pub fn new(name: String, oid: Oid, kind: Kind, schema: String) -> Other { Other(Arc::new(OtherInner { name: name, oid: oid, @@ -243,8 +243,9 @@ impl Error for WrongType { } } -impl WrongTypeNew for WrongType { - fn new(ty: Type) -> WrongType { +impl WrongType { + #[doc(hidden)] + pub fn new(ty: Type) -> WrongType { WrongType(ty) } } diff --git a/postgres/src/types/rustc_serialize.rs b/postgres-shared/src/types/rustc_serialize.rs similarity index 100% rename from postgres/src/types/rustc_serialize.rs rename to postgres-shared/src/types/rustc_serialize.rs diff --git a/postgres/src/types/serde_json.rs b/postgres-shared/src/types/serde_json.rs similarity index 100% rename from postgres/src/types/serde_json.rs rename to postgres-shared/src/types/serde_json.rs diff --git a/postgres/src/types/special.rs b/postgres-shared/src/types/special.rs similarity index 100% rename from postgres/src/types/special.rs rename to postgres-shared/src/types/special.rs diff --git a/postgres/src/types/time.rs b/postgres-shared/src/types/time.rs similarity index 100% rename from postgres/src/types/time.rs rename to postgres-shared/src/types/time.rs diff --git a/postgres/src/types/type_gen.rs b/postgres-shared/src/types/type_gen.rs similarity index 100% rename from postgres/src/types/type_gen.rs rename to postgres-shared/src/types/type_gen.rs diff --git a/postgres/src/types/uuid.rs b/postgres-shared/src/types/uuid.rs similarity index 100% rename from postgres/src/types/uuid.rs rename to postgres-shared/src/types/uuid.rs diff --git a/postgres/Cargo.toml b/postgres/Cargo.toml index 1d89e01c..d65f474d 100644 --- a/postgres/Cargo.toml +++ b/postgres/Cargo.toml @@ -21,17 +21,18 @@ name = "test" path = "tests/test.rs" [features] -with-bit-vec = ["bit-vec"] -with-chrono = ["chrono"] -with-eui48 = ["eui48"] +with-bit-vec = ["postgres-shared/with-bit-vec"] +with-chrono = ["postgres-shared/with-chrono"] +with-eui48 = ["postgres-shared/with-eui48"] +with-serde_json = ["postgres-shared/with-serde_json"] +with-time = ["postgres-shared/time"] +with-uuid = ["postgres-shared/with-uuid"] + with-openssl = ["openssl"] with-native-tls = ["native-tls"] with-rustc-serialize = ["rustc-serialize"] with-schannel = ["schannel"] with-security-framework = ["security-framework"] -with-serde_json = ["serde_json"] -with-time = ["time"] -with-uuid = ["uuid"] no-logging = [] @@ -41,17 +42,12 @@ fallible-iterator = "0.1.3" hex = "0.2" log = "0.3" postgres-protocol = "0.2" -bit-vec = { version = "0.4", optional = true } -chrono = { version = "0.2.14", optional = true } -eui48 = { version = "0.1", optional = true } + openssl = { version = "0.9", optional = true } native-tls = { version = "0.1", optional = true } rustc-serialize = { version = "0.3", optional = true } schannel = { version = "0.1", optional = true } security-framework = { version = "0.1.2", optional = true } -serde_json = { version = ">= 0.6, < 0.9", optional = true } -time = { version = "0.1.14", optional = true } -uuid = { version = ">= 0.1, < 0.4", optional = true } postgres-shared = { path = "../postgres-shared" } diff --git a/postgres/src/lib.rs b/postgres/src/lib.rs index 8fa3ffe0..fdc2ce25 100644 --- a/postgres/src/lib.rs +++ b/postgres/src/lib.rs @@ -77,6 +77,8 @@ extern crate hex; #[macro_use] extern crate log; extern crate postgres_protocol; +#[macro_use] +#[macro_export] extern crate postgres_shared; use fallible_iterator::FallibleIterator; @@ -101,7 +103,7 @@ use priv_io::MessageStream; use rows::{Rows, LazyRows}; use stmt::{Statement, Column}; use transaction::{Transaction, IsolationLevel}; -use types::{IsNull, Kind, Type, SessionInfo, Oid, Other, WrongType, ToSql, FromSql, Field}; +use types::{IsNull, Kind, Type, SessionInfo, Oid, Other, ToSql, FromSql, Field}; #[macro_use] mod macros; @@ -1360,10 +1362,6 @@ trait LazyRowsNew<'trans, 'stmt> { -> LazyRows<'trans, 'stmt>; } -trait SessionInfoNew<'a> { - fn new(params: &'a HashMap) -> SessionInfo<'a>; -} - trait StatementInternals<'conn> { fn new(conn: &'conn Connection, info: Arc, @@ -1384,14 +1382,6 @@ trait NotificationsNew<'conn> { fn new(conn: &'conn Connection) -> Notifications<'conn>; } -trait WrongTypeNew { - fn new(ty: Type) -> WrongType; -} - -trait FieldNew { - fn new(name: String, type_: Type) -> Field; -} - trait TransactionInternals<'conn> { fn new(conn: &'conn Connection, depth: u32) -> Transaction<'conn>; diff --git a/postgres/src/rows.rs b/postgres/src/rows.rs index f1d2117f..1c3a47a0 100644 --- a/postgres/src/rows.rs +++ b/postgres/src/rows.rs @@ -10,7 +10,7 @@ use std::io; use std::ops::Deref; use std::slice; -use {Result, SessionInfoNew, RowsNew, LazyRowsNew, StatementInternals, WrongTypeNew}; +use {Result, RowsNew, LazyRowsNew, StatementInternals}; use transaction::Transaction; use types::{FromSql, SessionInfo, WrongType}; use stmt::{Statement, Column}; diff --git a/postgres/src/stmt.rs b/postgres/src/stmt.rs index fbe235f9..88761b18 100644 --- a/postgres/src/stmt.rs +++ b/postgres/src/stmt.rs @@ -14,7 +14,7 @@ use types::{SessionInfo, Type, ToSql}; use rows::{Rows, LazyRows}; use transaction::Transaction; use {bad_response, err, Connection, StatementInternals, Result, RowsNew, InnerConnection, - SessionInfoNew, LazyRowsNew, ColumnNew, StatementInfo, TransactionInternals}; + LazyRowsNew, ColumnNew, StatementInfo, TransactionInternals}; /// A prepared statement. pub struct Statement<'conn> { diff --git a/postgres/src/types.rs b/postgres/src/types.rs new file mode 100644 index 00000000..c7b3f281 --- /dev/null +++ b/postgres/src/types.rs @@ -0,0 +1,4 @@ +//! Traits dealing with Postgres data types + +#[doc(inline)] +pub use postgres_shared::types::*;