Skip to content

Commit d08dc13

Browse files
committed
Move types out to postgres-shared
1 parent e675ee7 commit d08dc13

20 files changed

+48
-41
lines changed

codegen/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod sqlstate;
99
mod type_gen;
1010

1111
fn main() {
12-
let path = Path::new("..");
12+
let path = Path::new("../postgres-shared/src");
1313
sqlstate::build(path);
1414
type_gen::build(path);
1515
}

codegen/src/sqlstate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct Code {
1313
}
1414

1515
pub fn build(path: &Path) {
16-
let mut file = BufWriter::new(File::create(path.join("postgres-shared/src/error/sqlstate.rs")).unwrap());
16+
let mut file = BufWriter::new(File::create(path.join("error/sqlstate.rs")).unwrap());
1717

1818
let codes = parse_codes();
1919

codegen/src/type_gen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct Type {
2020
}
2121

2222
pub fn build(path: &Path) {
23-
let mut file = BufWriter::new(File::create(path.join("postgres/src/types/type_gen.rs")).unwrap());
23+
let mut file = BufWriter::new(File::create(path.join("types/type_gen.rs")).unwrap());
2424

2525
let ranges = parse_ranges();
2626
let types = parse_types(&ranges);

postgres-shared/Cargo.toml

+15
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,23 @@ name = "postgres-shared"
33
version = "0.1.0"
44
authors = ["Steven Fackler <[email protected]>"]
55

6+
[features]
7+
with-bit-vec = ["bit-vec"]
8+
with-chrono = ["chrono"]
9+
with-eui48 = ["eui48"]
10+
with-serde_json = ["serde_json"]
11+
with-time = ["time"]
12+
with-uuid = ["uuid"]
13+
614
[dependencies]
715
hex = "0.2"
816
fallible-iterator = "0.1.3"
917
phf = "=0.7.20"
1018
postgres-protocol = "0.2"
19+
20+
bit-vec = { version = "0.4", optional = true }
21+
chrono = { version = "0.2.14", optional = true }
22+
eui48 = { version = "0.1", optional = true }
23+
serde_json = { version = ">= 0.6, < 0.9", optional = true }
24+
time = { version = "0.1.14", optional = true }
25+
uuid = { version = ">= 0.1, < 0.4", optional = true }

postgres-shared/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::ops::Range;
1010

1111
pub mod error;
1212
pub mod params;
13+
pub mod types;
1314

1415
pub struct RowData {
1516
buf: Vec<u8>,
File renamed without changes.
File renamed without changes.
File renamed without changes.

postgres/src/types/mod.rs renamed to postgres-shared/src/types/mod.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! Traits dealing with Postgres data types
2-
31
use fallible_iterator::FallibleIterator;
42
use postgres_protocol;
53
use postgres_protocol::types::{self, ArrayDimension};
@@ -13,7 +11,6 @@ pub use postgres_protocol::Oid;
1311

1412
pub use self::type_gen::Type;
1513
pub use self::special::{Date, Timestamp};
16-
use {SessionInfoNew, OtherNew, WrongTypeNew, FieldNew};
1714

1815
/// Generates a simple implementation of `ToSql::accepts` which accepts the
1916
/// types passed to it.
@@ -88,8 +85,9 @@ pub struct SessionInfo<'a> {
8885
parameters: &'a HashMap<String, String>,
8986
}
9087

91-
impl<'a> SessionInfoNew<'a> for SessionInfo<'a> {
92-
fn new(parameters: &'a HashMap<String, String>) -> SessionInfo<'a> {
88+
impl<'a> SessionInfo<'a> {
89+
#[doc(hidden)]
90+
pub fn new(parameters: &'a HashMap<String, String>) -> SessionInfo<'a> {
9391
SessionInfo { parameters: parameters }
9492
}
9593
}
@@ -142,8 +140,9 @@ impl Field {
142140
}
143141
}
144142

145-
impl FieldNew for Field {
146-
fn new(name: String, type_: Type) -> Field {
143+
impl Field {
144+
#[doc(hidden)]
145+
pub fn new(name: String, type_: Type) -> Field {
147146
Field {
148147
name: name,
149148
type_: type_,
@@ -174,8 +173,9 @@ struct OtherInner {
174173
schema: String,
175174
}
176175

177-
impl OtherNew for Other {
178-
fn new(name: String, oid: Oid, kind: Kind, schema: String) -> Other {
176+
impl Other {
177+
#[doc(hidden)]
178+
pub fn new(name: String, oid: Oid, kind: Kind, schema: String) -> Other {
179179
Other(Arc::new(OtherInner {
180180
name: name,
181181
oid: oid,
@@ -243,8 +243,9 @@ impl Error for WrongType {
243243
}
244244
}
245245

246-
impl WrongTypeNew for WrongType {
247-
fn new(ty: Type) -> WrongType {
246+
impl WrongType {
247+
#[doc(hidden)]
248+
pub fn new(ty: Type) -> WrongType {
248249
WrongType(ty)
249250
}
250251
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

postgres/Cargo.toml

+8-12
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ name = "test"
2121
path = "tests/test.rs"
2222

2323
[features]
24-
with-bit-vec = ["bit-vec"]
25-
with-chrono = ["chrono"]
26-
with-eui48 = ["eui48"]
24+
with-bit-vec = ["postgres-shared/with-bit-vec"]
25+
with-chrono = ["postgres-shared/with-chrono"]
26+
with-eui48 = ["postgres-shared/with-eui48"]
27+
with-serde_json = ["postgres-shared/with-serde_json"]
28+
with-time = ["postgres-shared/time"]
29+
with-uuid = ["postgres-shared/with-uuid"]
30+
2731
with-openssl = ["openssl"]
2832
with-native-tls = ["native-tls"]
2933
with-rustc-serialize = ["rustc-serialize"]
3034
with-schannel = ["schannel"]
3135
with-security-framework = ["security-framework"]
32-
with-serde_json = ["serde_json"]
33-
with-time = ["time"]
34-
with-uuid = ["uuid"]
3536

3637
no-logging = []
3738

@@ -41,17 +42,12 @@ fallible-iterator = "0.1.3"
4142
hex = "0.2"
4243
log = "0.3"
4344
postgres-protocol = "0.2"
44-
bit-vec = { version = "0.4", optional = true }
45-
chrono = { version = "0.2.14", optional = true }
46-
eui48 = { version = "0.1", optional = true }
45+
4746
openssl = { version = "0.9", optional = true }
4847
native-tls = { version = "0.1", optional = true }
4948
rustc-serialize = { version = "0.3", optional = true }
5049
schannel = { version = "0.1", optional = true }
5150
security-framework = { version = "0.1.2", optional = true }
52-
serde_json = { version = ">= 0.6, < 0.9", optional = true }
53-
time = { version = "0.1.14", optional = true }
54-
uuid = { version = ">= 0.1, < 0.4", optional = true }
5551

5652
postgres-shared = { path = "../postgres-shared" }
5753

postgres/src/lib.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ extern crate hex;
7777
#[macro_use]
7878
extern crate log;
7979
extern crate postgres_protocol;
80+
#[macro_use]
81+
#[macro_export]
8082
extern crate postgres_shared;
8183

8284
use fallible_iterator::FallibleIterator;
@@ -101,7 +103,7 @@ use priv_io::MessageStream;
101103
use rows::{Rows, LazyRows};
102104
use stmt::{Statement, Column};
103105
use transaction::{Transaction, IsolationLevel};
104-
use types::{IsNull, Kind, Type, SessionInfo, Oid, Other, WrongType, ToSql, FromSql, Field};
106+
use types::{IsNull, Kind, Type, SessionInfo, Oid, Other, ToSql, FromSql, Field};
105107

106108
#[macro_use]
107109
mod macros;
@@ -1360,10 +1362,6 @@ trait LazyRowsNew<'trans, 'stmt> {
13601362
-> LazyRows<'trans, 'stmt>;
13611363
}
13621364

1363-
trait SessionInfoNew<'a> {
1364-
fn new(params: &'a HashMap<String, String>) -> SessionInfo<'a>;
1365-
}
1366-
13671365
trait StatementInternals<'conn> {
13681366
fn new(conn: &'conn Connection,
13691367
info: Arc<StatementInfo>,
@@ -1384,14 +1382,6 @@ trait NotificationsNew<'conn> {
13841382
fn new(conn: &'conn Connection) -> Notifications<'conn>;
13851383
}
13861384

1387-
trait WrongTypeNew {
1388-
fn new(ty: Type) -> WrongType;
1389-
}
1390-
1391-
trait FieldNew {
1392-
fn new(name: String, type_: Type) -> Field;
1393-
}
1394-
13951385
trait TransactionInternals<'conn> {
13961386
fn new(conn: &'conn Connection, depth: u32) -> Transaction<'conn>;
13971387

postgres/src/rows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::io;
1010
use std::ops::Deref;
1111
use std::slice;
1212

13-
use {Result, SessionInfoNew, RowsNew, LazyRowsNew, StatementInternals, WrongTypeNew};
13+
use {Result, RowsNew, LazyRowsNew, StatementInternals};
1414
use transaction::Transaction;
1515
use types::{FromSql, SessionInfo, WrongType};
1616
use stmt::{Statement, Column};

postgres/src/stmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use types::{SessionInfo, Type, ToSql};
1414
use rows::{Rows, LazyRows};
1515
use transaction::Transaction;
1616
use {bad_response, err, Connection, StatementInternals, Result, RowsNew, InnerConnection,
17-
SessionInfoNew, LazyRowsNew, ColumnNew, StatementInfo, TransactionInternals};
17+
LazyRowsNew, ColumnNew, StatementInfo, TransactionInternals};
1818

1919
/// A prepared statement.
2020
pub struct Statement<'conn> {

postgres/src/types.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! Traits dealing with Postgres data types
2+
3+
#[doc(inline)]
4+
pub use postgres_shared::types::*;

0 commit comments

Comments
 (0)