Skip to content

Commit fc8ab87

Browse files
committed
Cleanup
1 parent 25b32e0 commit fc8ab87

3 files changed

Lines changed: 45 additions & 38 deletions

File tree

src/notification.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct Notification {
1818
pub payload: String,
1919
}
2020

21-
/// An iterator over asynchronous notifications.
21+
/// Notifications from the Postgres backend.
2222
pub struct Notifications<'conn> {
2323
conn: &'conn Connection,
2424
}

src/rows.rs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -163,29 +163,6 @@ impl<'a> Row<'a> {
163163
self.stmt.columns()
164164
}
165165

166-
/// Retrieves the contents of a field of the row.
167-
///
168-
/// A field can be accessed by the name or index of its column, though
169-
/// access by index is more efficient. Rows are 0-indexed.
170-
///
171-
/// Returns an `Error` value if the index does not reference a column or
172-
/// the return type is not compatible with the Postgres type.
173-
pub fn get_opt<I, T>(&self, idx: I) -> Result<T>
174-
where I: RowIndex,
175-
T: FromSql
176-
{
177-
let idx = try!(idx.idx(self.stmt).ok_or(Error::InvalidColumn));
178-
let ty = self.stmt.columns()[idx].type_();
179-
if !<T as FromSql>::accepts(ty) {
180-
return Err(Error::WrongType(ty.clone()));
181-
}
182-
let conn = self.stmt.conn().conn.borrow();
183-
match self.data[idx] {
184-
Some(ref data) => FromSql::from_sql(ty, &mut &**data, &SessionInfo::new(&*conn)),
185-
None => FromSql::from_sql_null(ty, &SessionInfo::new(&*conn)),
186-
}
187-
}
188-
189166
/// Retrieves the contents of a field of the row.
190167
///
191168
/// A field can be accessed by the name or index of its column, though
@@ -209,15 +186,45 @@ impl<'a> Row<'a> {
209186
/// }
210187
/// ```
211188
pub fn get<I, T>(&self, idx: I) -> T
212-
where I: RowIndex + fmt::Debug + Clone,
189+
where I: RowIndex + fmt::Debug,
213190
T: FromSql
214191
{
215-
match self.get_opt(idx.clone()) {
192+
match self.get_inner(&idx) {
216193
Ok(ok) => ok,
217194
Err(err) => panic!("error retrieving column {:?}: {:?}", idx, err),
218195
}
219196
}
220197

198+
/// Retrieves the contents of a field of the row.
199+
///
200+
/// A field can be accessed by the name or index of its column, though
201+
/// access by index is more efficient. Rows are 0-indexed.
202+
///
203+
/// Returns an `Error` value if the index does not reference a column or
204+
/// the return type is not compatible with the Postgres type.
205+
pub fn get_opt<I, T>(&self, idx: I) -> Result<T>
206+
where I: RowIndex,
207+
T: FromSql
208+
{
209+
self.get_inner(&idx)
210+
}
211+
212+
fn get_inner<I, T>(&self, idx: &I) -> Result<T>
213+
where I: RowIndex,
214+
T: FromSql
215+
{
216+
let idx = try!(idx.idx(self.stmt).ok_or(Error::InvalidColumn));
217+
let ty = self.stmt.columns()[idx].type_();
218+
if !<T as FromSql>::accepts(ty) {
219+
return Err(Error::WrongType(ty.clone()));
220+
}
221+
let conn = self.stmt.conn().conn.borrow();
222+
match self.data[idx] {
223+
Some(ref data) => FromSql::from_sql(ty, &mut &**data, &SessionInfo::new(&*conn)),
224+
None => FromSql::from_sql_null(ty, &SessionInfo::new(&*conn)),
225+
}
226+
}
227+
221228
/// Retrieves the specified field as a raw buffer of Postgres data.
222229
///
223230
/// # Panics

src/stmt.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,18 @@ impl ColumnNew for Column {
538538
}
539539
}
540540

541+
impl Column {
542+
/// The name of the column.
543+
pub fn name(&self) -> &str {
544+
&self.name
545+
}
546+
547+
/// The type of the data in the column.
548+
pub fn type_(&self) -> &Type {
549+
&self.type_
550+
}
551+
}
552+
541553
/// A struct containing information relevant for a `COPY` operation.
542554
pub struct CopyInfo<'a> {
543555
conn: RefMut<'a, InnerConnection>,
@@ -590,18 +602,6 @@ impl<W: Write> WriteWithInfo for W {
590602
}
591603
}
592604

593-
impl Column {
594-
/// The name of the column.
595-
pub fn name(&self) -> &str {
596-
&self.name
597-
}
598-
599-
/// The type of the data in the column.
600-
pub fn type_(&self) -> &Type {
601-
&self.type_
602-
}
603-
}
604-
605605
/// The format of a portion of COPY query data.
606606
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
607607
pub enum Format {

0 commit comments

Comments
 (0)