Skip to content

Commit d1c412b

Browse files
committed
More ~str -> StrBuf
1 parent dc6bb57 commit d1c412b

4 files changed

Lines changed: 43 additions & 43 deletions

File tree

src/error.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ pub enum PostgresErrorPosition {
415415
/// The byte position
416416
pub position: uint,
417417
/// A query generated by the Postgres server
418-
pub query: ~str
418+
pub query: StrBuf
419419
}
420420
}
421421

@@ -424,71 +424,71 @@ pub struct PostgresDbError {
424424
/// The field contents are ERROR, FATAL, or PANIC (in an error message),
425425
/// or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message), or a
426426
/// localized translation of one of these.
427-
pub severity: ~str,
427+
pub severity: StrBuf,
428428
/// The SQLSTATE code for the error.
429429
pub code: PostgresSqlState,
430430
/// The primary human-readable error message. This should be accurate but
431431
/// terse (typically one line).
432-
pub message: ~str,
432+
pub message: StrBuf,
433433
/// An optional secondary error message carrying more detail about the
434434
/// problem. Might run to multiple lines.
435-
pub detail: Option<~str>,
435+
pub detail: Option<StrBuf>,
436436
/// An optional suggestion what to do about the problem. This is intended
437437
/// to differ from Detail in that it offers advice (potentially
438438
/// inappropriate) rather than hard facts. Might run to multiple lines.
439-
pub hint: Option<~str>,
439+
pub hint: Option<StrBuf>,
440440
/// An optional error cursor position into either the original query string
441441
/// or an internally generated query.
442442
pub position: Option<PostgresErrorPosition>,
443443
/// An indication of the context in which the error occurred. Presently
444444
/// this includes a call stack traceback of active procedural language
445445
/// functions and internally-generated queries. The trace is one entry per
446446
/// line, most recent first.
447-
pub where: Option<~str>,
447+
pub where: Option<StrBuf>,
448448
/// If the error was associated with a specific database object, the name
449449
/// of the schema containing that object, if any. (PostgreSQL 9.3+)
450-
pub schema: Option<~str>,
450+
pub schema: Option<StrBuf>,
451451
/// If the error was associated with a specific table, the name of the
452452
/// table. (Refer to the schema name field for the name of the table's
453453
/// schema.) (PostgreSQL 9.3+)
454-
pub table: Option<~str>,
454+
pub table: Option<StrBuf>,
455455
/// If the error was associated with a specific table column, the name of
456456
/// the column. (Refer to the schema and table name fields to identify the
457457
/// table.) (PostgreSQL 9.3+)
458-
pub column: Option<~str>,
458+
pub column: Option<StrBuf>,
459459
/// If the error was associated with a specific data type, the name of the
460460
/// data type. (Refer to the schema name field for the name of the data
461461
/// type's schema.) (PostgreSQL 9.3+)
462-
pub datatype: Option<~str>,
462+
pub datatype: Option<StrBuf>,
463463
/// If the error was associated with a specific constraint, the name of the
464464
/// constraint. Refer to fields listed above for the associated table or
465465
/// domain. (For this purpose, indexes are treated as constraints, even if
466466
/// they weren't created with constraint syntax.) (PostgreSQL 9.3+)
467-
pub constraint: Option<~str>,
467+
pub constraint: Option<StrBuf>,
468468
/// The file name of the source-code location where the error was reported.
469-
pub file: ~str,
469+
pub file: StrBuf,
470470
/// The line number of the source-code location where the error was
471471
/// reported.
472472
pub line: uint,
473473
/// The name of the source-code routine reporting the error.
474-
pub routine: ~str
474+
pub routine: StrBuf
475475
}
476476

477477
impl PostgresDbError {
478478
#[doc(hidden)]
479-
pub fn new(fields: Vec<(u8, ~str)>) -> PostgresDbError {
480-
let mut map: HashMap<u8, ~str> = fields.move_iter().collect();
479+
pub fn new(fields: Vec<(u8, StrBuf)>) -> PostgresDbError {
480+
let mut map: HashMap<_, _> = fields.move_iter().collect();
481481
PostgresDbError {
482482
severity: map.pop(&('S' as u8)).unwrap(),
483-
code: PostgresSqlState::from_code(map.pop(&('C' as u8)).unwrap()),
483+
code: PostgresSqlState::from_code(map.pop(&('C' as u8)).unwrap().as_slice()),
484484
message: map.pop(&('M' as u8)).unwrap(),
485485
detail: map.pop(&('D' as u8)),
486486
hint: map.pop(&('H' as u8)),
487487
position: match map.pop(&('P' as u8)) {
488-
Some(pos) => Some(Position(FromStr::from_str(pos).unwrap())),
488+
Some(pos) => Some(Position(FromStr::from_str(pos.as_slice()).unwrap())),
489489
None => match map.pop(&('p' as u8)) {
490490
Some(pos) => Some(InternalPosition {
491-
position: FromStr::from_str(pos).unwrap(),
491+
position: FromStr::from_str(pos.as_slice()).unwrap(),
492492
query: map.pop(&('q' as u8)).unwrap()
493493
}),
494494
None => None
@@ -501,7 +501,7 @@ impl PostgresDbError {
501501
datatype: map.pop(&('d' as u8)),
502502
constraint: map.pop(&('n' as u8)),
503503
file: map.pop(&('F' as u8)).unwrap(),
504-
line: FromStr::from_str(map.pop(&('L' as u8)).unwrap()).unwrap(),
504+
line: FromStr::from_str(map.pop(&('L' as u8)).unwrap().as_slice()).unwrap(),
505505
routine: map.pop(&('R' as u8)).unwrap()
506506
}
507507
}

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ pub struct PostgresNotification {
323323
/// The process ID of the notifying backend process
324324
pub pid: i32,
325325
/// The name of the channel that the notify has been raised on
326-
pub channel: ~str,
326+
pub channel: StrBuf,
327327
/// The "payload" string passed from the notifying process
328-
pub payload: ~str,
328+
pub payload: StrBuf,
329329
}
330330

331331
/// An iterator over asynchronous notifications
@@ -1174,7 +1174,7 @@ impl<'conn> PostgresStatement<'conn> {
11741174
return Err(PgDbError(PostgresDbError::new(fields)));
11751175
}
11761176
CommandComplete { tag } => {
1177-
let s = tag.split(' ').last().unwrap();
1177+
let s = tag.as_slice().split(' ').last().unwrap();
11781178
num = FromStr::from_str(s).unwrap_or(0);
11791179
break;
11801180
}
@@ -1230,7 +1230,7 @@ impl<'conn> PostgresStatement<'conn> {
12301230
#[deriving(Eq)]
12311231
pub struct ResultDescription {
12321232
/// The name of the column
1233-
pub name: ~str,
1233+
pub name: StrBuf,
12341234
/// The type of the data in the column
12351235
pub ty: PostgresType
12361236
}

src/message.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ pub enum BackendMessage {
2424
BindComplete,
2525
CloseComplete,
2626
CommandComplete {
27-
pub tag: ~str
27+
pub tag: StrBuf,
2828
},
2929
DataRow {
3030
pub row: Vec<Option<Vec<u8>>>
3131
},
3232
EmptyQueryResponse,
3333
ErrorResponse {
34-
pub fields: Vec<(u8, ~str)>
34+
pub fields: Vec<(u8, StrBuf)>
3535
},
3636
NoData,
3737
NoticeResponse {
38-
pub fields: Vec<(u8, ~str)>
38+
pub fields: Vec<(u8, StrBuf)>
3939
},
4040
NotificationResponse {
4141
pub pid: i32,
42-
pub channel: ~str,
43-
pub payload: ~str
42+
pub channel: StrBuf,
43+
pub payload: StrBuf,
4444
},
4545
ParameterDescription {
4646
pub types: Vec<Oid>
4747
},
4848
ParameterStatus {
49-
pub parameter: ~str,
50-
pub value: ~str
49+
pub parameter: StrBuf,
50+
pub value: StrBuf,
5151
},
5252
ParseComplete,
5353
PortalSuspended,
@@ -60,7 +60,7 @@ pub enum BackendMessage {
6060
}
6161

6262
pub struct RowDescriptionEntry {
63-
pub name: ~str,
63+
pub name: StrBuf,
6464
pub table_oid: Oid,
6565
pub column_id: i16,
6666
pub type_oid: Oid,
@@ -237,14 +237,14 @@ impl<W: Writer> WriteMessage for W {
237237

238238
#[doc(hidden)]
239239
trait ReadCStr {
240-
fn read_cstr(&mut self) -> IoResult<~str>;
240+
fn read_cstr(&mut self) -> IoResult<StrBuf>;
241241
}
242242

243243
impl<R: Buffer> ReadCStr for R {
244-
fn read_cstr(&mut self) -> IoResult<~str> {
244+
fn read_cstr(&mut self) -> IoResult<StrBuf> {
245245
let mut buf = try!(self.read_until(0));
246246
buf.pop();
247-
Ok(StrBuf::from_utf8(buf).unwrap().into_owned())
247+
Ok(StrBuf::from_utf8(buf).unwrap())
248248
}
249249
}
250250

@@ -294,7 +294,7 @@ impl<R: Reader> ReadMessage for R {
294294
}
295295
}
296296

297-
fn read_fields(buf: &mut MemReader) -> IoResult<Vec<(u8, ~str)>> {
297+
fn read_fields(buf: &mut MemReader) -> IoResult<Vec<(u8, StrBuf)>> {
298298
let mut fields = Vec::new();
299299
loop {
300300
let ty = try!(buf.read_u8());

src/test.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ fn test_result_descriptions() {
365365
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
366366
let stmt = or_fail!(conn.prepare("SELECT 1::INT as a, 'hi'::VARCHAR as b"));
367367
assert!(stmt.result_descriptions() ==
368-
[ResultDescription { name: "a".to_owned(), ty: PgInt4},
369-
ResultDescription { name: "b".to_owned(), ty: PgVarchar}]);
368+
[ResultDescription { name: "a".to_strbuf(), ty: PgInt4},
369+
ResultDescription { name: "b".to_strbuf(), ty: PgVarchar}]);
370370
}
371371

372372
#[test]
@@ -869,21 +869,21 @@ fn test_notification_iterator_some() {
869869

870870
check_notification(PostgresNotification {
871871
pid: 0,
872-
channel: "test_notification_iterator_one_channel".to_owned(),
873-
payload: "hello".to_owned()
872+
channel: "test_notification_iterator_one_channel".to_strbuf(),
873+
payload: "hello".to_strbuf()
874874
}, it.next());
875875
check_notification(PostgresNotification {
876876
pid: 0,
877-
channel: "test_notification_iterator_one_channel2".to_owned(),
878-
payload: "world".to_owned()
877+
channel: "test_notification_iterator_one_channel2".to_strbuf(),
878+
payload: "world".to_strbuf()
879879
}, it.next());
880880
assert!(it.next().is_none());
881881

882882
or_fail!(conn.execute("NOTIFY test_notification_iterator_one_channel, '!'", []));
883883
check_notification(PostgresNotification {
884884
pid: 0,
885-
channel: "test_notification_iterator_one_channel".to_owned(),
886-
payload: "!".to_owned()
885+
channel: "test_notification_iterator_one_channel".to_strbuf(),
886+
payload: "!".to_strbuf()
887887
}, it.next());
888888
assert!(it.next().is_none());
889889
}

0 commit comments

Comments
 (0)