Skip to content

Commit d684e5e

Browse files
committed
Remove internals traits
1 parent bec973c commit d684e5e

File tree

9 files changed

+70
-169
lines changed

9 files changed

+70
-169
lines changed

postgres/src/lib.rs

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ use tls::TlsHandshake;
9898
use notification::{Notifications, Notification};
9999
use params::{IntoConnectParams, User};
100100
use priv_io::MessageStream;
101-
use rows::{Rows, LazyRows};
101+
use rows::Rows;
102102
use stmt::{Statement, Column};
103103
use transaction::{Transaction, IsolationLevel};
104104
use types::{IsNull, Kind, Type, Oid, ToSql, FromSql, Field, OID, NAME, CHAR};
@@ -1467,58 +1467,3 @@ fn err(fields: &mut ErrorFields) -> Error {
14671467
Err(err) => Error::Io(err),
14681468
}
14691469
}
1470-
1471-
trait RowsNew {
1472-
fn new(stmt: &Statement, data: Vec<RowData>) -> Rows<'static>;
1473-
}
1474-
1475-
trait LazyRowsNew<'trans, 'stmt> {
1476-
fn new(
1477-
stmt: &'stmt Statement<'stmt>,
1478-
data: VecDeque<RowData>,
1479-
name: String,
1480-
row_limit: i32,
1481-
more_rows: bool,
1482-
finished: bool,
1483-
trans: &'trans Transaction<'trans>,
1484-
) -> LazyRows<'trans, 'stmt>;
1485-
}
1486-
1487-
trait StatementInternals<'conn> {
1488-
fn new(
1489-
conn: &'conn Connection,
1490-
info: Arc<StatementInfo>,
1491-
next_portal_id: Cell<u32>,
1492-
finished: bool,
1493-
) -> Statement<'conn>;
1494-
1495-
fn conn(&self) -> &'conn Connection;
1496-
1497-
fn info(&self) -> &Arc<StatementInfo>;
1498-
1499-
fn into_query(self, params: &[&ToSql]) -> Result<Rows<'static>>;
1500-
}
1501-
1502-
trait ColumnNew {
1503-
fn new(name: String, type_: Type) -> Column;
1504-
}
1505-
1506-
trait NotificationsNew<'conn> {
1507-
fn new(conn: &'conn Connection) -> Notifications<'conn>;
1508-
}
1509-
1510-
trait TransactionInternals<'conn> {
1511-
fn new(conn: &'conn Connection, depth: u32) -> Transaction<'conn>;
1512-
1513-
fn conn(&self) -> &'conn Connection;
1514-
1515-
fn depth(&self) -> u32;
1516-
}
1517-
1518-
trait ConfigInternals {
1519-
fn build_command(&self, s: &mut String);
1520-
}
1521-
1522-
trait IsolationLevelNew {
1523-
fn new(level: &str) -> Result<IsolationLevel>;
1524-
}

postgres/src/notification.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use postgres_protocol::message::backend;
88
#[doc(inline)]
99
pub use postgres_shared::Notification;
1010

11-
use {desynchronized, Result, Connection, NotificationsNew};
11+
use {desynchronized, Result, Connection};
1212
use error::Error;
1313

1414
/// Notifications from the Postgres backend.
@@ -25,6 +25,10 @@ impl<'a> fmt::Debug for Notifications<'a> {
2525
}
2626

2727
impl<'conn> Notifications<'conn> {
28+
pub(crate) fn new(conn: &'conn Connection) -> Notifications<'conn> {
29+
Notifications { conn: conn }
30+
}
31+
2832
/// Returns the number of pending notifications.
2933
pub fn len(&self) -> usize {
3034
self.conn.0.borrow().notifications.len()
@@ -78,12 +82,6 @@ impl<'a, 'conn> IntoFallibleIterator for &'a Notifications<'conn> {
7882
}
7983
}
8084

81-
impl<'conn> NotificationsNew<'conn> for Notifications<'conn> {
82-
fn new(conn: &'conn Connection) -> Notifications<'conn> {
83-
Notifications { conn: conn }
84-
}
85-
}
86-
8785
/// A fallible iterator over pending notifications.
8886
pub struct Iter<'a> {
8987
conn: &'a Connection,

postgres/src/rows.rs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::slice;
1212
use std::sync::Arc;
1313
use std::marker::PhantomData;
1414

15-
use {Result, RowsNew, LazyRowsNew, StatementInternals, StatementInfo};
15+
use {Result, StatementInfo};
1616
use transaction::Transaction;
1717
use types::{FromSql, WrongType};
1818
use stmt::{Statement, Column};
@@ -42,16 +42,6 @@ pub struct Rows<'compat> {
4242
_marker: PhantomData<&'compat u8>,
4343
}
4444

45-
impl RowsNew for Rows<'static> {
46-
fn new(stmt: &Statement, data: Vec<RowData>) -> Rows<'static> {
47-
Rows {
48-
stmt_info: stmt.info().clone(),
49-
data: data,
50-
_marker: PhantomData,
51-
}
52-
}
53-
}
54-
5545
impl<'a> fmt::Debug for Rows<'a> {
5646
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
5747
fmt.debug_struct("Rows")
@@ -61,6 +51,16 @@ impl<'a> fmt::Debug for Rows<'a> {
6151
}
6252
}
6353

54+
impl Rows<'static> {
55+
pub(crate) fn new(stmt: &Statement, data: Vec<RowData>) -> Rows<'static> {
56+
Rows {
57+
stmt_info: stmt.info().clone(),
58+
data: data,
59+
_marker: PhantomData,
60+
}
61+
}
62+
}
63+
6464
impl<'rows> Rows<'rows> {
6565
/// Returns a slice describing the columns of the `Rows`.
6666
pub fn columns(&self) -> &[Column] {
@@ -302,28 +302,6 @@ pub struct LazyRows<'trans, 'stmt> {
302302
_trans: &'trans Transaction<'trans>,
303303
}
304304

305-
impl<'trans, 'stmt> LazyRowsNew<'trans, 'stmt> for LazyRows<'trans, 'stmt> {
306-
fn new(
307-
stmt: &'stmt Statement<'stmt>,
308-
data: VecDeque<RowData>,
309-
name: String,
310-
row_limit: i32,
311-
more_rows: bool,
312-
finished: bool,
313-
trans: &'trans Transaction<'trans>,
314-
) -> LazyRows<'trans, 'stmt> {
315-
LazyRows {
316-
stmt: stmt,
317-
data: data,
318-
name: name,
319-
row_limit: row_limit,
320-
more_rows: more_rows,
321-
finished: finished,
322-
_trans: trans,
323-
}
324-
}
325-
}
326-
327305
impl<'a, 'b> Drop for LazyRows<'a, 'b> {
328306
fn drop(&mut self) {
329307
if !self.finished {
@@ -344,6 +322,26 @@ impl<'a, 'b> fmt::Debug for LazyRows<'a, 'b> {
344322
}
345323

346324
impl<'trans, 'stmt> LazyRows<'trans, 'stmt> {
325+
pub(crate) fn new(
326+
stmt: &'stmt Statement<'stmt>,
327+
data: VecDeque<RowData>,
328+
name: String,
329+
row_limit: i32,
330+
more_rows: bool,
331+
finished: bool,
332+
trans: &'trans Transaction<'trans>,
333+
) -> LazyRows<'trans, 'stmt> {
334+
LazyRows {
335+
stmt: stmt,
336+
data: data,
337+
name: name,
338+
row_limit: row_limit,
339+
more_rows: more_rows,
340+
finished: finished,
341+
_trans: trans,
342+
}
343+
}
344+
347345
fn finish_inner(&mut self) -> Result<()> {
348346
let mut conn = self.stmt.conn().0.borrow_mut();
349347
check_desync!(conn);

postgres/src/stmt.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use error::Error;
1313
use types::{Type, ToSql};
1414
use rows::{Rows, LazyRows};
1515
use transaction::Transaction;
16-
use {bad_response, err, Connection, StatementInternals, Result, RowsNew, LazyRowsNew, ColumnNew,
17-
StatementInfo, TransactionInternals};
16+
use {bad_response, err, Connection, Result, StatementInfo};
1817

1918
/// A prepared statement.
2019
pub struct Statement<'conn> {
@@ -36,8 +35,8 @@ impl<'conn> Drop for Statement<'conn> {
3635
}
3736
}
3837

39-
impl<'conn> StatementInternals<'conn> for Statement<'conn> {
40-
fn new(
38+
impl<'conn> Statement<'conn> {
39+
pub(crate) fn new(
4140
conn: &'conn Connection,
4241
info: Arc<StatementInfo>,
4342
next_portal_id: Cell<u32>,
@@ -51,23 +50,21 @@ impl<'conn> StatementInternals<'conn> for Statement<'conn> {
5150
}
5251
}
5352

54-
fn info(&self) -> &Arc<StatementInfo> {
53+
pub(crate) fn info(&self) -> &Arc<StatementInfo> {
5554
&self.info
5655
}
5756

58-
fn conn(&self) -> &'conn Connection {
57+
pub(crate) fn conn(&self) -> &'conn Connection {
5958
self.conn
6059
}
6160

62-
fn into_query(self, params: &[&ToSql]) -> Result<Rows<'static>> {
61+
pub(crate) fn into_query(self, params: &[&ToSql]) -> Result<Rows<'static>> {
6362
check_desync!(self.conn);
6463
let mut rows = vec![];
6564
self.inner_query("", 0, params, |row| rows.push(row))?;
6665
Ok(Rows::new(&self, rows))
6766
}
68-
}
6967

70-
impl<'conn> Statement<'conn> {
7168
fn finish_inner(&mut self) -> Result<()> {
7269
if self.finished {
7370
Ok(())
@@ -563,16 +560,14 @@ pub struct Column {
563560
type_: Type,
564561
}
565562

566-
impl ColumnNew for Column {
567-
fn new(name: String, type_: Type) -> Column {
563+
impl Column {
564+
pub(crate) fn new(name: String, type_: Type) -> Column {
568565
Column {
569566
name: name,
570567
type_: type_,
571568
}
572569
}
573-
}
574570

575-
impl Column {
576571
/// The name of the column.
577572
pub fn name(&self) -> &str {
578573
&self.name

postgres/src/transaction.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::cell::Cell;
44
use std::fmt;
55
use std::ascii::AsciiExt;
66

7-
use {bad_response, Result, Connection, TransactionInternals, ConfigInternals, IsolationLevelNew};
7+
use {bad_response, Result, Connection};
88
use error::Error;
99
use rows::Rows;
1010
use stmt::Statement;
@@ -31,8 +31,8 @@ pub enum IsolationLevel {
3131
Serializable,
3232
}
3333

34-
impl IsolationLevelNew for IsolationLevel {
35-
fn new(raw: &str) -> Result<IsolationLevel> {
34+
impl IsolationLevel {
35+
pub(crate) fn new(raw: &str) -> Result<IsolationLevel> {
3636
if raw.eq_ignore_ascii_case("READ UNCOMMITTED") {
3737
Ok(IsolationLevel::ReadUncommitted)
3838
} else if raw.eq_ignore_ascii_case("READ COMMITTED") {
@@ -45,9 +45,7 @@ impl IsolationLevelNew for IsolationLevel {
4545
Err(Error::Io(bad_response()))
4646
}
4747
}
48-
}
4948

50-
impl IsolationLevel {
5149
fn to_sql(&self) -> &'static str {
5250
match *self {
5351
IsolationLevel::ReadUncommitted => "READ UNCOMMITTED",
@@ -76,8 +74,8 @@ impl Default for Config {
7674
}
7775
}
7876

79-
impl ConfigInternals for Config {
80-
fn build_command(&self, s: &mut String) {
77+
impl Config {
78+
pub(crate) fn build_command(&self, s: &mut String) {
8179
let mut first = true;
8280

8381
if let Some(isolation_level) = self.isolation_level {
@@ -109,9 +107,7 @@ impl ConfigInternals for Config {
109107
}
110108
}
111109
}
112-
}
113110

114-
impl Config {
115111
/// Creates a new `Config` with no configuration overrides.
116112
pub fn new() -> Config {
117113
Config::default()
@@ -172,8 +168,8 @@ impl<'conn> Drop for Transaction<'conn> {
172168
}
173169
}
174170

175-
impl<'conn> TransactionInternals<'conn> for Transaction<'conn> {
176-
fn new(conn: &'conn Connection, depth: u32) -> Transaction<'conn> {
171+
impl<'conn> Transaction<'conn> {
172+
pub(crate) fn new(conn: &'conn Connection, depth: u32) -> Transaction<'conn> {
177173
Transaction {
178174
conn: conn,
179175
depth: depth,
@@ -183,16 +179,14 @@ impl<'conn> TransactionInternals<'conn> for Transaction<'conn> {
183179
}
184180
}
185181

186-
fn conn(&self) -> &'conn Connection {
182+
pub(crate) fn conn(&self) -> &'conn Connection {
187183
self.conn
188184
}
189185

190-
fn depth(&self) -> u32 {
186+
pub(crate) fn depth(&self) -> u32 {
191187
self.depth
192188
}
193-
}
194189

195-
impl<'conn> Transaction<'conn> {
196190
fn finish_inner(&mut self) -> Result<()> {
197191
let mut conn = self.conn.0.borrow_mut();
198192
debug_assert!(self.depth == conn.trans_depth);

tokio-postgres/src/lib.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,24 +1139,3 @@ where
11391139
{
11401140
io::Error::new(io::ErrorKind::InvalidInput, "unexpected message").into()
11411141
}
1142-
1143-
trait RowNew {
1144-
fn new(columns: Arc<Vec<Column>>, data: RowData) -> Row;
1145-
}
1146-
1147-
trait StatementNew {
1148-
fn new(
1149-
close_sender: Sender<(u8, String)>,
1150-
name: String,
1151-
params: Vec<Type>,
1152-
columns: Arc<Vec<Column>>,
1153-
) -> Statement;
1154-
1155-
fn columns_arc(&self) -> &Arc<Vec<Column>>;
1156-
1157-
fn name(&self) -> &str;
1158-
}
1159-
1160-
trait TransactionNew {
1161-
fn new(c: Connection) -> Transaction;
1162-
}

tokio-postgres/src/rows.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::sync::Arc;
99
#[doc(inline)]
1010
pub use postgres_shared::rows::RowIndex;
1111

12-
use RowNew;
1312
use types::{WrongType, FromSql};
1413

1514
/// A row from Postgres.
@@ -18,16 +17,14 @@ pub struct Row {
1817
data: RowData,
1918
}
2019

21-
impl RowNew for Row {
22-
fn new(columns: Arc<Vec<Column>>, data: RowData) -> Row {
20+
impl Row {
21+
pub(crate) fn new(columns: Arc<Vec<Column>>, data: RowData) -> Row {
2322
Row {
2423
columns: columns,
2524
data: data,
2625
}
2726
}
28-
}
2927

30-
impl Row {
3128
/// Returns information about the columns in the row.
3229
pub fn columns(&self) -> &[Column] {
3330
&self.columns

0 commit comments

Comments
 (0)