Skip to content

Commit 92a3593

Browse files
committed
Update for upstream changes
String vs Show still needs to be resolved, but it compiles now
1 parent 4f157bb commit 92a3593

10 files changed

Lines changed: 112 additions & 173 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ optional = true
3535
version = "0.1"
3636

3737
[dev-dependencies]
38-
url = "0.2"
38+
#url = "0.2"
3939

src/error.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,9 @@ impl fmt::Show for ConnectError {
444444
ConnectError::NoSslSupport =>
445445
write!(fmt, "The server does not support SSL"),
446446
ConnectError::SslError(ref err) =>
447-
write!(fmt, "Error initiating SSL session: {}", err),
447+
write!(fmt, "Error initiating SSL session: {:?}", err),
448448
ConnectError::IoError(ref err) =>
449-
write!(fmt, "Error communicating with server: {}", err),
449+
write!(fmt, "Error communicating with server: {:?}", err),
450450
ConnectError::BadResponse =>
451451
write!(fmt, "The server returned an unexpected response"),
452452
}
@@ -457,11 +457,11 @@ impl fmt::Show for ConnectError {
457457
#[derive(Clone, PartialEq, Eq)]
458458
pub enum ErrorPosition {
459459
/// A position in the original query
460-
Normal(uint),
460+
Normal(usize),
461461
/// A position in an internally generated query
462462
Internal {
463463
/// The byte position
464-
position: uint,
464+
position: usize,
465465
/// A query generated by the Postgres server
466466
query: String
467467
}
@@ -518,7 +518,7 @@ pub struct DbError {
518518
pub file: String,
519519
/// The line number of the source-code location where the error was
520520
/// reported.
521-
pub line: uint,
521+
pub line: usize,
522522
/// The name of the source-code routine reporting the error.
523523
pub routine: String
524524
}
@@ -603,9 +603,9 @@ pub enum Error {
603603
/// An incorrect number of parameters were bound to a statement
604604
WrongParamCount {
605605
/// The expected number of parameters
606-
expected: uint,
606+
expected: usize,
607607
/// The actual number of parameters
608-
actual: uint,
608+
actual: usize,
609609
},
610610
/// An attempt was made to convert between incompatible Rust and Postgres
611611
/// types

src/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub enum InternalStream {
3535
}
3636

3737
impl Reader for InternalStream {
38-
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
38+
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
3939
match *self {
4040
InternalStream::Tcp(ref mut s) => s.read(buf),
4141
InternalStream::Unix(ref mut s) => s.read(buf),

src/lib.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#![doc(html_root_url="https://sfackler.github.io/doc")]
5353
#![feature(plugin, unsafe_destructor, slicing_syntax, old_orphan_check)]
5454
#![warn(missing_docs)]
55+
#![allow(unstable)]
5556

5657
#[macro_use]
5758
extern crate log;
@@ -374,7 +375,7 @@ pub fn cancel_query<T>(params: T, ssl: &SslMode, data: CancelData)
374375

375376
struct InnerConnection {
376377
stream: BufferedStream<MaybeSslStream<InternalStream>>,
377-
next_stmt_id: uint,
378+
next_stmt_id: usize,
378379
notice_handler: Box<NoticeHandler>,
379380
notifications: RingBuf<Notification>,
380381
cancel_data: CancelData,
@@ -666,7 +667,7 @@ impl InnerConnection {
666667
fn set_type_names<'a, I>(&mut self, mut it: I) -> Result<()>
667668
where I: Iterator<Item=&'a mut Type> {
668669
for ty in it {
669-
if let &Type::Unknown { oid, ref mut name } = ty {
670+
if let &mut Type::Unknown { oid, ref mut name } = ty {
670671
*name = try!(self.get_type_name(oid));
671672
}
672673
}
@@ -958,7 +959,7 @@ impl Connection {
958959
/// or execution of the statement.
959960
///
960961
/// On success, returns the number of rows modified or 0 if not applicable.
961-
pub fn execute(&self, query: &str, params: &[&ToSql]) -> Result<uint> {
962+
pub fn execute(&self, query: &str, params: &[&ToSql]) -> Result<usize> {
962963
let (param_types, result_desc) = try!(self.conn.borrow_mut().raw_prepare("", query));
963964
let stmt = Statement {
964965
conn: self,
@@ -1104,7 +1105,7 @@ impl<'conn> Transaction<'conn> {
11041105
}
11051106

11061107
/// Like `Connection::execute`.
1107-
pub fn execute(&self, query: &str, params: &[&ToSql]) -> Result<uint> {
1108+
pub fn execute(&self, query: &str, params: &[&ToSql]) -> Result<usize> {
11081109
self.conn.execute(query, params)
11091110
}
11101111

@@ -1196,7 +1197,7 @@ pub struct Statement<'conn> {
11961197
name: String,
11971198
param_types: Vec<Type>,
11981199
result_desc: Vec<ResultDescription>,
1199-
next_portal_id: Cell<uint>,
1200+
next_portal_id: Cell<usize>,
12001201
finished: bool,
12011202
}
12021203

@@ -1303,7 +1304,7 @@ impl<'conn> Statement<'conn> {
13031304
/// Err(err) => println!("Error executing query: {}", err)
13041305
/// }
13051306
/// ```
1306-
pub fn execute(&self, params: &[&ToSql]) -> Result<uint> {
1307+
pub fn execute(&self, params: &[&ToSql]) -> Result<usize> {
13071308
check_desync!(self.conn);
13081309
try!(self.inner_execute("", 0, params));
13091310

@@ -1489,7 +1490,7 @@ impl<'stmt> Iterator for Rows<'stmt> {
14891490
}
14901491

14911492
#[inline]
1492-
fn size_hint(&self) -> (uint, Option<uint>) {
1493+
fn size_hint(&self) -> (usize, Option<usize>) {
14931494
let lower = self.data.len();
14941495
let upper = if self.more_rows {
14951496
None
@@ -1508,7 +1509,7 @@ pub struct Row<'stmt> {
15081509

15091510
impl<'stmt> Row<'stmt> {
15101511
/// Returns the number of values in the row
1511-
pub fn len(&self) -> uint {
1512+
pub fn len(&self) -> usize {
15121513
self.data.len()
15131514
}
15141515

@@ -1553,7 +1554,7 @@ impl<'stmt> Row<'stmt> {
15531554
pub fn get<I, T>(&self, idx: I) -> T where I: RowIndex + fmt::Show + Clone, T: FromSql {
15541555
match self.get_opt(idx.clone()) {
15551556
Ok(ok) => ok,
1556-
Err(err) => panic!("error retrieving column {}: {}", idx, err)
1557+
Err(err) => panic!("error retrieving column {:?}: {:?}", idx, err)
15571558
}
15581559
}
15591560
}
@@ -1562,12 +1563,12 @@ impl<'stmt> Row<'stmt> {
15621563
pub trait RowIndex {
15631564
/// Returns the index of the appropriate column, or `None` if no such
15641565
/// column exists.
1565-
fn idx(&self, stmt: &Statement) -> Option<uint>;
1566+
fn idx(&self, stmt: &Statement) -> Option<usize>;
15661567
}
15671568

1568-
impl RowIndex for uint {
1569+
impl RowIndex for usize {
15691570
#[inline]
1570-
fn idx(&self, stmt: &Statement) -> Option<uint> {
1571+
fn idx(&self, stmt: &Statement) -> Option<usize> {
15711572
if *self >= stmt.result_desc.len() {
15721573
None
15731574
} else {
@@ -1578,7 +1579,7 @@ impl RowIndex for uint {
15781579

15791580
impl<'a> RowIndex for &'a str {
15801581
#[inline]
1581-
fn idx(&self, stmt: &Statement) -> Option<uint> {
1582+
fn idx(&self, stmt: &Statement) -> Option<usize> {
15821583
stmt.result_descriptions().iter().position(|d| d.name == *self)
15831584
}
15841585
}
@@ -1603,7 +1604,7 @@ impl<'trans, 'stmt> Iterator for LazyRows<'trans, 'stmt> {
16031604
self.result.try_next()
16041605
}
16051606

1606-
fn size_hint(&self) -> (uint, Option<uint>) {
1607+
fn size_hint(&self) -> (usize, Option<usize>) {
16071608
self.result.size_hint()
16081609
}
16091610
}
@@ -1643,7 +1644,7 @@ impl<'a> CopyInStatement<'a> {
16431644
/// providing a single result row.
16441645
///
16451646
/// Returns the number of rows copied.
1646-
pub fn execute<'b, I, J>(&self, mut rows: I) -> Result<uint>
1647+
pub fn execute<'b, I, J>(&self, mut rows: I) -> Result<usize>
16471648
where I: Iterator<Item=J>, J: Iterator<Item=&'b (ToSql + 'b)> {
16481649
let mut conn = self.conn.conn.borrow_mut();
16491650

@@ -1705,7 +1706,7 @@ impl<'a> CopyInStatement<'a> {
17051706
// FIXME this is not the right way to handle this
17061707
try_desync!(conn, conn.stream.write_message(
17071708
&CopyFail {
1708-
message: &*err.to_string(),
1709+
message: &*format!("{:?}", err),
17091710
}));
17101711
break 'l;
17111712
}
@@ -1770,7 +1771,7 @@ pub trait GenericConnection {
17701771
fn prepare<'a>(&'a self, query: &str) -> Result<Statement<'a>>;
17711772

17721773
/// Like `Connection::execute`.
1773-
fn execute(&self, query: &str, params: &[&ToSql]) -> Result<uint>;
1774+
fn execute(&self, query: &str, params: &[&ToSql]) -> Result<usize>;
17741775

17751776
/// Like `Connection::prepare_copy_in`.
17761777
fn prepare_copy_in<'a>(&'a self, table: &str, columns: &[&str])
@@ -1788,7 +1789,7 @@ impl GenericConnection for Connection {
17881789
self.prepare(query)
17891790
}
17901791

1791-
fn execute(&self, query: &str, params: &[&ToSql]) -> Result<uint> {
1792+
fn execute(&self, query: &str, params: &[&ToSql]) -> Result<usize> {
17921793
self.execute(query, params)
17931794
}
17941795

@@ -1811,7 +1812,7 @@ impl<'a> GenericConnection for Transaction<'a> {
18111812
self.prepare(query)
18121813
}
18131814

1814-
fn execute(&self, query: &str, params: &[&ToSql]) -> Result<uint> {
1815+
fn execute(&self, query: &str, params: &[&ToSql]) -> Result<usize> {
18151816
self.execute(query, params)
18161817
}
18171818

src/message.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<W: Writer> WriteMessage for W {
171171
None => try!(buf.write_be_i32(-1)),
172172
Some(ref value) => {
173173
try!(buf.write_be_i32(value.len() as i32));
174-
try!(buf.write(value[]));
174+
try!(buf.write(&**value));
175175
}
176176
}
177177
}
@@ -230,8 +230,8 @@ impl<W: Writer> WriteMessage for W {
230230
StartupMessage { version, parameters } => {
231231
try!(buf.write_be_u32(version));
232232
for &(ref k, ref v) in parameters.iter() {
233-
try!(buf.write_cstr(k[]));
234-
try!(buf.write_cstr(v[]));
233+
try!(buf.write_cstr(&**k));
234+
try!(buf.write_cstr(&**v));
235235
}
236236
try!(buf.write_u8(0));
237237
}
@@ -246,7 +246,7 @@ impl<W: Writer> WriteMessage for W {
246246

247247
// add size of length value
248248
try!(self.write_be_i32((buf.len() + mem::size_of::<i32>()) as i32));
249-
try!(self.write(buf[]));
249+
try!(self.write(&*buf));
250250

251251
Ok(())
252252
}
@@ -286,7 +286,7 @@ impl<R: Buffer+Timeout> ReadMessage for R {
286286
let ident = try!(ident);
287287

288288
// subtract size of length value
289-
let len = try!(self.read_be_u32()) as uint - mem::size_of::<i32>();
289+
let len = try!(self.read_be_u32()) as usize - mem::size_of::<i32>();
290290
let mut rdr = LimitReader::new(self.by_ref(), len);
291291

292292
let ret = match ident {
@@ -360,13 +360,13 @@ fn read_fields<R: Buffer>(buf: &mut R) -> IoResult<Vec<(u8, String)>> {
360360
}
361361

362362
fn read_data_row<R: Buffer>(buf: &mut R) -> IoResult<BackendMessage> {
363-
let len = try!(buf.read_be_i16()) as uint;
363+
let len = try!(buf.read_be_i16()) as usize;
364364
let mut values = Vec::with_capacity(len);
365365

366366
for _ in range(0, len) {
367367
let val = match try!(buf.read_be_i32()) {
368368
-1 => None,
369-
len => Some(try!(buf.read_exact(len as uint)))
369+
len => Some(try!(buf.read_exact(len as usize)))
370370
};
371371
values.push(val);
372372
}
@@ -396,7 +396,7 @@ fn read_auth_message<R: Buffer>(buf: &mut R) -> IoResult<BackendMessage> {
396396
}
397397

398398
fn read_parameter_description<R: Buffer>(buf: &mut R) -> IoResult<BackendMessage> {
399-
let len = try!(buf.read_be_i16()) as uint;
399+
let len = try!(buf.read_be_i16()) as usize;
400400
let mut types = Vec::with_capacity(len);
401401

402402
for _ in range(0, len) {
@@ -407,7 +407,7 @@ fn read_parameter_description<R: Buffer>(buf: &mut R) -> IoResult<BackendMessage
407407
}
408408

409409
fn read_row_description<R: Buffer>(buf: &mut R) -> IoResult<BackendMessage> {
410-
let len = try!(buf.read_be_i16()) as uint;
410+
let len = try!(buf.read_be_i16()) as usize;
411411
let mut types = Vec::with_capacity(len);
412412

413413
for _ in range(0, len) {

src/types/mod.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use serialize::json;
33
use std::collections::HashMap;
44
use std::io::net::ip::IpAddr;
5+
use std::fmt;
56

67
use Result;
78
use error::Error;
@@ -198,6 +199,18 @@ macro_rules! make_postgres_type {
198199
}
199200
}
200201

202+
impl fmt::String for Type {
203+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
204+
let s = match *self {
205+
$(
206+
Type::$variant => stringify!($variant),
207+
)+
208+
Type::Unknown { ref name, .. } => &**name,
209+
};
210+
write!(fmt, "{}", s)
211+
}
212+
}
213+
201214
impl Type {
202215
/// Creates a `Type` from an OID.
203216
///
@@ -385,7 +398,7 @@ impl RawFromSql for IpAddr {
385398
return Err(Error::BadData);
386399
}
387400
let mut buf = [0u8; 16];
388-
try!(raw.read_at_least(nb as uint, &mut buf));
401+
try!(raw.read_at_least(nb as usize, &mut buf));
389402
let mut buf: &[u8] = &buf;
390403

391404
match family {
@@ -451,7 +464,7 @@ impl FromSql for Option<HashMap<String, Option<String>>> {
451464

452465
for _ in range(0, count) {
453466
let key_len = try!(rdr.read_be_i32());
454-
let key = try!(rdr.read_exact(key_len as uint));
467+
let key = try!(rdr.read_exact(key_len as usize));
455468
let key = match String::from_utf8(key) {
456469
Ok(key) => key,
457470
Err(_) => return Err(Error::BadData),
@@ -461,7 +474,7 @@ impl FromSql for Option<HashMap<String, Option<String>>> {
461474
let val = if val_len < 0 {
462475
None
463476
} else {
464-
let val = try!(rdr.read_exact(val_len as uint));
477+
let val = try!(rdr.read_exact(val_len as usize));
465478
match String::from_utf8(val) {
466479
Ok(val) => Some(val),
467480
Err(_) => return Err(Error::BadData),

0 commit comments

Comments
 (0)