Skip to content

Commit 6394dc1

Browse files
committed
Cleanup
1 parent 792d7bf commit 6394dc1

File tree

5 files changed

+14
-60
lines changed

5 files changed

+14
-60
lines changed

postgres-shared/src/error/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Errors.
2+
13
use fallible_iterator::FallibleIterator;
24
use postgres_protocol::message::backend::ErrorFields;
35
use std::error;

postgres-shared/src/stmt.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use types::Type;
22

3+
/// Information about a column of a Postgres query.
4+
#[derive(Debug)]
35
pub struct Column {
46
name: String,
57
type_: Type,
@@ -14,10 +16,12 @@ impl Column {
1416
}
1517
}
1618

19+
/// Returns the name of the column.
1720
pub fn name(&self) -> &str {
1821
&self.name
1922
}
2023

24+
/// Returns the type of the column.
2125
pub fn type_(&self) -> &Type {
2226
&self.type_
2327
}

postgres-shared/src/types/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Types.
2+
13
use fallible_iterator::FallibleIterator;
24
use postgres_protocol;
35
use postgres_protocol::types::{self, ArrayDimension};

postgres/src/rows.rs

+3-34
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ use std::ops::Deref;
1111
use std::slice;
1212
use std::sync::Arc;
1313

14+
#[doc(inline)]
15+
pub use postgres_shared::rows::RowIndex;
16+
1417
use {Error, Result, StatementInfo};
1518
use error;
1619
use transaction::Transaction;
@@ -251,40 +254,6 @@ impl<'a> Row<'a> {
251254
}
252255
}
253256

254-
/// A trait implemented by types that can index into columns of a row.
255-
pub trait RowIndex {
256-
/// Returns the index of the appropriate column, or `None` if no such
257-
/// column exists.
258-
fn idx(&self, _: &[Column]) -> Option<usize>;
259-
}
260-
261-
impl RowIndex for usize {
262-
#[inline]
263-
fn idx(&self, columns: &[Column]) -> Option<usize> {
264-
if *self >= columns.len() {
265-
None
266-
} else {
267-
Some(*self)
268-
}
269-
}
270-
}
271-
272-
impl<'a> RowIndex for &'a str {
273-
#[inline]
274-
fn idx(&self, columns: &[Column]) -> Option<usize> {
275-
if let Some(idx) = columns.iter().position(|d| d.name() == *self) {
276-
return Some(idx);
277-
};
278-
279-
// FIXME ASCII-only case insensitivity isn't really the right thing to
280-
// do. Postgres itself uses a dubious wrapper around tolower and JDBC
281-
// uses the US locale.
282-
columns.iter().position(
283-
|d| d.name().eq_ignore_ascii_case(*self),
284-
)
285-
}
286-
}
287-
288257
/// A lazily-loaded iterator over the resulting rows of a query.
289258
pub struct LazyRows<'trans, 'stmt> {
290259
stmt: &'stmt Statement<'stmt>,

postgres/src/stmt.rs

+3-26
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use std::sync::Arc;
99
use postgres_protocol::message::{backend, frontend};
1010
use postgres_shared::rows::RowData;
1111

12+
#[doc(inline)]
13+
pub use postgres_shared::stmt::Column;
14+
1215
use types::{Type, ToSql};
1316
use rows::{Rows, LazyRows};
1417
use transaction::Transaction;
@@ -554,32 +557,6 @@ fn fill_copy_buf<R: ReadWithInfo>(buf: &mut [u8], r: &mut R, info: &CopyInfo) ->
554557
Ok(nread)
555558
}
556559

557-
/// Information about a column of the result of a query.
558-
#[derive(PartialEq, Eq, Clone, Debug)]
559-
pub struct Column {
560-
name: String,
561-
type_: Type,
562-
}
563-
564-
impl Column {
565-
pub(crate) fn new(name: String, type_: Type) -> Column {
566-
Column {
567-
name: name,
568-
type_: type_,
569-
}
570-
}
571-
572-
/// The name of the column.
573-
pub fn name(&self) -> &str {
574-
&self.name
575-
}
576-
577-
/// The type of the data in the column.
578-
pub fn type_(&self) -> &Type {
579-
&self.type_
580-
}
581-
}
582-
583560
/// A struct containing information relevant for a `COPY` operation.
584561
pub struct CopyInfo {
585562
format: Format,

0 commit comments

Comments
 (0)