Skip to content

Commit 0707887

Browse files
committed
Get rid of StringRow
It's not exposed by any methods, and the API isn't great.
1 parent e3f2eb7 commit 0707887

File tree

3 files changed

+8
-54
lines changed

3 files changed

+8
-54
lines changed

tokio-postgres/src/proto/connect_once.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(clippy::large_enum_variant)]
22

3+
use fallible_iterator::FallibleIterator;
34
use futures::{try_ready, Async, Future, Poll, Stream};
45
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
56
use std::io;
@@ -92,7 +93,8 @@ where
9293

9394
match try_ready!(state.stream.poll()) {
9495
Some(row) => {
95-
if row.get(0) == Some("on") {
96+
let range = row.ranges().next().map_err(Error::parse)?.and_then(|r| r);
97+
if range.map(|r| &row.buffer()[r]) == Some(b"on") {
9698
Err(Error::connect(io::Error::new(
9799
io::ErrorKind::PermissionDenied,
98100
"database does not allow writes",

tokio-postgres/src/proto/simple_query.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use futures::sync::mpsc;
22
use futures::{Async, Poll, Stream};
3-
use postgres_protocol::message::backend::Message;
3+
use postgres_protocol::message::backend::{DataRowBody, Message};
44
use std::mem;
55

66
use crate::proto::client::{Client, PendingRequest};
7-
use crate::{Error, StringRow};
7+
use crate::Error;
88

99
pub enum State {
1010
Start {
@@ -20,10 +20,10 @@ pub enum State {
2020
pub struct SimpleQueryStream(State);
2121

2222
impl Stream for SimpleQueryStream {
23-
type Item = StringRow;
23+
type Item = DataRowBody;
2424
type Error = Error;
2525

26-
fn poll(&mut self) -> Poll<Option<StringRow>, Error> {
26+
fn poll(&mut self) -> Poll<Option<DataRowBody>, Error> {
2727
loop {
2828
match mem::replace(&mut self.0, State::Done) {
2929
State::Start { client, request } => {
@@ -48,8 +48,7 @@ impl Stream for SimpleQueryStream {
4848
}
4949
Some(Message::DataRow(body)) => {
5050
self.0 = State::ReadResponse { receiver };
51-
let row = StringRow::new(body)?;
52-
return Ok(Async::Ready(Some(row)));
51+
return Ok(Async::Ready(Some(body)));
5352
}
5453
Some(Message::ErrorResponse(body)) => return Err(Error::db(body)),
5554
Some(Message::ReadyForQuery(_)) => return Ok(Async::Ready(None)),

tokio-postgres/src/row.rs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -134,50 +134,3 @@ impl Row {
134134
value.map(Some).map_err(Error::from_sql)
135135
}
136136
}
137-
138-
pub struct StringRow {
139-
body: DataRowBody,
140-
ranges: Vec<Option<Range<usize>>>,
141-
}
142-
143-
impl StringRow {
144-
#[allow(clippy::new_ret_no_self)]
145-
pub(crate) fn new(body: DataRowBody) -> Result<StringRow, Error> {
146-
let ranges = body.ranges().collect().map_err(Error::parse)?;
147-
Ok(StringRow { body, ranges })
148-
}
149-
150-
pub fn is_empty(&self) -> bool {
151-
self.len() == 0
152-
}
153-
154-
pub fn len(&self) -> usize {
155-
self.ranges.len()
156-
}
157-
158-
pub fn get(&self, idx: usize) -> Option<&str> {
159-
match self.try_get(idx) {
160-
Ok(Some(ok)) => ok,
161-
Err(err) => panic!("error retrieving column {}: {}", idx, err),
162-
Ok(None) => panic!("no such column {}", idx),
163-
}
164-
}
165-
166-
#[allow(clippy::option_option)] // FIXME
167-
pub fn try_get(&self, idx: usize) -> Result<Option<Option<&str>>, Error> {
168-
let buf = match self.ranges.get(idx) {
169-
Some(range) => range.clone().map(|r| &self.body.buffer()[r]),
170-
None => return Ok(None),
171-
};
172-
173-
let v = match buf {
174-
Some(buf) => {
175-
let s = str::from_utf8(buf).map_err(|e| Error::from_sql(Box::new(e)))?;
176-
Some(s)
177-
}
178-
None => None,
179-
};
180-
181-
Ok(Some(v))
182-
}
183-
}

0 commit comments

Comments
 (0)