Skip to content

Commit dcd4704

Browse files
committed
More ~str -> StrBuf
1 parent 1909bd4 commit dcd4704

3 files changed

Lines changed: 24 additions & 19 deletions

File tree

src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ struct InnerPostgresConnection {
405405
notice_handler: Box<PostgresNoticeHandler:Send>,
406406
notifications: RingBuf<PostgresNotification>,
407407
cancel_data: PostgresCancelData,
408-
unknown_types: HashMap<Oid, ~str>,
408+
unknown_types: HashMap<Oid, StrBuf>,
409409
desynchronized: bool,
410410
finished: bool,
411411
canary: u32,
@@ -638,7 +638,7 @@ impl InnerPostgresConnection {
638638
Ok(())
639639
}
640640

641-
fn get_type_name(&mut self, oid: Oid) -> PostgresResult<~str> {
641+
fn get_type_name(&mut self, oid: Oid) -> PostgresResult<StrBuf> {
642642
match self.unknown_types.find(&oid) {
643643
Some(name) => return Ok(name.clone()),
644644
None => {}
@@ -666,7 +666,7 @@ impl InnerPostgresConnection {
666666
}
667667

668668
fn quick_query(&mut self, query: &str)
669-
-> PostgresResult<Vec<Vec<Option<~str>>>> {
669+
-> PostgresResult<Vec<Vec<Option<StrBuf>>>> {
670670
check_desync!(self);
671671
try_pg!(self.write_messages([Query { query: query }]));
672672

@@ -676,8 +676,8 @@ impl InnerPostgresConnection {
676676
ReadyForQuery { .. } => break,
677677
DataRow { row } => {
678678
result.push(row.move_iter().map(|opt| {
679-
opt.map(|b| StrBuf::from_utf8(b).unwrap().into_owned())
680-
}).collect());
679+
opt.map(|b| StrBuf::from_utf8(b).unwrap())
680+
}).collect());
681681
}
682682
ErrorResponse { fields } => {
683683
try!(self.wait_for_ready());
@@ -746,7 +746,7 @@ impl PostgresConnection {
746746
/// let params = PostgresConnectParams {
747747
/// target: TargetUnix(some_crazy_path),
748748
/// port: None,
749-
/// user: Some("postgres".to_owned()),
749+
/// user: Some("postgres".to_strbuf()),
750750
/// password: None,
751751
/// database: None,
752752
/// options: Vec::new(),
@@ -882,7 +882,7 @@ impl PostgresConnection {
882882
}
883883

884884
fn quick_query(&self, query: &str)
885-
-> PostgresResult<Vec<Vec<Option<~str>>>> {
885+
-> PostgresResult<Vec<Vec<Option<StrBuf>>>> {
886886
self.conn.borrow_mut().quick_query(query)
887887
}
888888

@@ -1403,7 +1403,7 @@ impl<'stmt, I: RowIndex+Clone+fmt::Show, T: FromSql> Index<I, T>
14031403
/// # let mut result = stmt.query([]).unwrap();
14041404
/// # let row = result.next().unwrap();
14051405
/// let foo: i32 = row[1];
1406-
/// let bar: ~str = row["bar"];
1406+
/// let bar: StrBuf = row["bar"];
14071407
/// ```
14081408
fn index(&self, idx: &I) -> T {
14091409
match self.get(idx.clone()) {

src/test.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,14 @@ fn test_unix_connection() {
112112
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
113113
let stmt = or_fail!(conn.prepare("SHOW unix_socket_directories"));
114114
let result = or_fail!(stmt.query([]));
115-
let unix_socket_directories: ~str = result.map(|row| row[1]).next().unwrap();
115+
let unix_socket_directories: StrBuf = result.map(|row| row[1]).next().unwrap();
116116

117117
if unix_socket_directories.is_empty() {
118118
fail!("can't test connect_unix; unix_socket_directories is empty");
119119
}
120120

121-
let unix_socket_directory = unix_socket_directories.splitn(',', 1).next().unwrap();
121+
let unix_socket_directory = unix_socket_directories.as_slice()
122+
.splitn(',', 1).next().unwrap();
122123

123124
let url = format!("postgres://postgres@{}", url::encode_component(unix_socket_directory));
124125
let conn = or_fail!(PostgresConnection::connect(url.as_slice(), &NoSsl));
@@ -469,7 +470,7 @@ fn test_bpchar_params() {
469470
)", []));
470471
or_fail!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($3)",
471472
[&Some("12345") as &ToSql, &Some("123") as &ToSql,
472-
&None::<~str> as &ToSql]));
473+
&None::<&'static str> as &ToSql]));
473474
let stmt = or_fail!(conn.prepare("SELECT b FROM foo ORDER BY id"));
474475
let res = or_fail!(stmt.query([]));
475476

@@ -989,6 +990,6 @@ fn test_pg_database_datname() {
989990
let mut result = or_fail!(stmt.query([]));
990991

991992
let next = result.next().unwrap();
992-
or_fail!(next.get::<uint, ~str>(1));
993-
or_fail!(next.get::<&str, ~str>("datname"));
993+
or_fail!(next.get::<uint, StrBuf>(1));
994+
or_fail!(next.get::<&str, StrBuf>("datname"));
994995
}

src/types/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ macro_rules! make_postgres_type(
8686
/// An unknown type
8787
PgUnknownType {
8888
/// The name of the type
89-
pub name: ~str,
89+
pub name: StrBuf,
9090
/// The OID of the type
9191
pub oid: Oid
9292
}
@@ -98,7 +98,7 @@ macro_rules! make_postgres_type(
9898
match oid {
9999
$($oid => $variant,)+
100100
// We have to load an empty string now, it'll get filled in later
101-
oid => PgUnknownType { name: "".to_owned(), oid: oid }
101+
oid => PgUnknownType { name: "".to_strbuf(), oid: oid }
102102
}
103103
}
104104

@@ -122,7 +122,8 @@ macro_rules! make_postgres_type(
122122
/// Returns the wire format needed for the value of `self`.
123123
pub fn result_format(&self) -> Format {
124124
match *self {
125-
PgUnknownType { name: ref name, .. } if "hstore" == *name => Binary,
125+
PgUnknownType { name: ref name, .. }
126+
if "hstore" == name.as_slice() => Binary,
126127
PgUnknownType { .. } => Text,
127128
_ => Binary
128129
}
@@ -477,7 +478,8 @@ impl FromSql for Option<HashMap<~str, Option<~str>>> {
477478
fn from_sql(ty: &PostgresType, raw: &Option<Vec<u8>>)
478479
-> PostgresResult<Option<HashMap<~str, Option<~str>>>> {
479480
match *ty {
480-
PgUnknownType { name: ref name, .. } if "hstore" == *name => {}
481+
PgUnknownType { name: ref name, .. }
482+
if "hstore" == name.as_slice() => {}
481483
_ => return Err(PgWrongType(ty.clone()))
482484
}
483485

@@ -792,7 +794,8 @@ impl ToSql for HashMap<~str, Option<~str>> {
792794
fn to_sql(&self, ty: &PostgresType)
793795
-> PostgresResult<(Format, Option<Vec<u8>>)> {
794796
match *ty {
795-
PgUnknownType { name: ref name, .. } if "hstore" == *name => {}
797+
PgUnknownType { name: ref name, .. }
798+
if "hstore" == name.as_slice() => {}
796799
_ => return Err(PgWrongType(ty.clone()))
797800
}
798801

@@ -821,7 +824,8 @@ impl ToSql for Option<HashMap<~str, Option<~str>>> {
821824
fn to_sql(&self, ty: &PostgresType)
822825
-> PostgresResult<(Format, Option<Vec<u8>>)> {
823826
match *ty {
824-
PgUnknownType { name: ref name, .. } if "hstore" == *name => {}
827+
PgUnknownType { name: ref name, .. }
828+
if "hstore" == name.as_slice() => {}
825829
_ => return Err(PgWrongType(ty.clone()))
826830
}
827831

0 commit comments

Comments
 (0)