More ~str -> StrBuf

This commit is contained in:
Steven Fackler 2014-05-12 22:05:37 -07:00
parent dc6bb579c2
commit d1c412b393
4 changed files with 43 additions and 43 deletions

View File

@ -415,7 +415,7 @@ pub enum PostgresErrorPosition {
/// The byte position /// The byte position
pub position: uint, pub position: uint,
/// A query generated by the Postgres server /// A query generated by the Postgres server
pub query: ~str pub query: StrBuf
} }
} }
@ -424,19 +424,19 @@ pub struct PostgresDbError {
/// The field contents are ERROR, FATAL, or PANIC (in an error message), /// The field contents are ERROR, FATAL, or PANIC (in an error message),
/// or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message), or a /// or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message), or a
/// localized translation of one of these. /// localized translation of one of these.
pub severity: ~str, pub severity: StrBuf,
/// The SQLSTATE code for the error. /// The SQLSTATE code for the error.
pub code: PostgresSqlState, pub code: PostgresSqlState,
/// The primary human-readable error message. This should be accurate but /// The primary human-readable error message. This should be accurate but
/// terse (typically one line). /// terse (typically one line).
pub message: ~str, pub message: StrBuf,
/// An optional secondary error message carrying more detail about the /// An optional secondary error message carrying more detail about the
/// problem. Might run to multiple lines. /// problem. Might run to multiple lines.
pub detail: Option<~str>, pub detail: Option<StrBuf>,
/// An optional suggestion what to do about the problem. This is intended /// An optional suggestion what to do about the problem. This is intended
/// to differ from Detail in that it offers advice (potentially /// to differ from Detail in that it offers advice (potentially
/// inappropriate) rather than hard facts. Might run to multiple lines. /// inappropriate) rather than hard facts. Might run to multiple lines.
pub hint: Option<~str>, pub hint: Option<StrBuf>,
/// An optional error cursor position into either the original query string /// An optional error cursor position into either the original query string
/// or an internally generated query. /// or an internally generated query.
pub position: Option<PostgresErrorPosition>, pub position: Option<PostgresErrorPosition>,
@ -444,51 +444,51 @@ pub struct PostgresDbError {
/// this includes a call stack traceback of active procedural language /// this includes a call stack traceback of active procedural language
/// functions and internally-generated queries. The trace is one entry per /// functions and internally-generated queries. The trace is one entry per
/// line, most recent first. /// line, most recent first.
pub where: Option<~str>, pub where: Option<StrBuf>,
/// If the error was associated with a specific database object, the name /// If the error was associated with a specific database object, the name
/// of the schema containing that object, if any. (PostgreSQL 9.3+) /// of the schema containing that object, if any. (PostgreSQL 9.3+)
pub schema: Option<~str>, pub schema: Option<StrBuf>,
/// If the error was associated with a specific table, the name of the /// If the error was associated with a specific table, the name of the
/// table. (Refer to the schema name field for the name of the table's /// table. (Refer to the schema name field for the name of the table's
/// schema.) (PostgreSQL 9.3+) /// schema.) (PostgreSQL 9.3+)
pub table: Option<~str>, pub table: Option<StrBuf>,
/// If the error was associated with a specific table column, the name of /// If the error was associated with a specific table column, the name of
/// the column. (Refer to the schema and table name fields to identify the /// the column. (Refer to the schema and table name fields to identify the
/// table.) (PostgreSQL 9.3+) /// table.) (PostgreSQL 9.3+)
pub column: Option<~str>, pub column: Option<StrBuf>,
/// If the error was associated with a specific data type, the name of the /// If the error was associated with a specific data type, the name of the
/// data type. (Refer to the schema name field for the name of the data /// data type. (Refer to the schema name field for the name of the data
/// type's schema.) (PostgreSQL 9.3+) /// type's schema.) (PostgreSQL 9.3+)
pub datatype: Option<~str>, pub datatype: Option<StrBuf>,
/// If the error was associated with a specific constraint, the name of the /// If the error was associated with a specific constraint, the name of the
/// constraint. Refer to fields listed above for the associated table or /// constraint. Refer to fields listed above for the associated table or
/// domain. (For this purpose, indexes are treated as constraints, even if /// domain. (For this purpose, indexes are treated as constraints, even if
/// they weren't created with constraint syntax.) (PostgreSQL 9.3+) /// they weren't created with constraint syntax.) (PostgreSQL 9.3+)
pub constraint: Option<~str>, pub constraint: Option<StrBuf>,
/// The file name of the source-code location where the error was reported. /// The file name of the source-code location where the error was reported.
pub file: ~str, pub file: StrBuf,
/// The line number of the source-code location where the error was /// The line number of the source-code location where the error was
/// reported. /// reported.
pub line: uint, pub line: uint,
/// The name of the source-code routine reporting the error. /// The name of the source-code routine reporting the error.
pub routine: ~str pub routine: StrBuf
} }
impl PostgresDbError { impl PostgresDbError {
#[doc(hidden)] #[doc(hidden)]
pub fn new(fields: Vec<(u8, ~str)>) -> PostgresDbError { pub fn new(fields: Vec<(u8, StrBuf)>) -> PostgresDbError {
let mut map: HashMap<u8, ~str> = fields.move_iter().collect(); let mut map: HashMap<_, _> = fields.move_iter().collect();
PostgresDbError { PostgresDbError {
severity: map.pop(&('S' as u8)).unwrap(), severity: map.pop(&('S' as u8)).unwrap(),
code: PostgresSqlState::from_code(map.pop(&('C' as u8)).unwrap()), code: PostgresSqlState::from_code(map.pop(&('C' as u8)).unwrap().as_slice()),
message: map.pop(&('M' as u8)).unwrap(), message: map.pop(&('M' as u8)).unwrap(),
detail: map.pop(&('D' as u8)), detail: map.pop(&('D' as u8)),
hint: map.pop(&('H' as u8)), hint: map.pop(&('H' as u8)),
position: match map.pop(&('P' as u8)) { position: match map.pop(&('P' as u8)) {
Some(pos) => Some(Position(FromStr::from_str(pos).unwrap())), Some(pos) => Some(Position(FromStr::from_str(pos.as_slice()).unwrap())),
None => match map.pop(&('p' as u8)) { None => match map.pop(&('p' as u8)) {
Some(pos) => Some(InternalPosition { Some(pos) => Some(InternalPosition {
position: FromStr::from_str(pos).unwrap(), position: FromStr::from_str(pos.as_slice()).unwrap(),
query: map.pop(&('q' as u8)).unwrap() query: map.pop(&('q' as u8)).unwrap()
}), }),
None => None None => None
@ -501,7 +501,7 @@ impl PostgresDbError {
datatype: map.pop(&('d' as u8)), datatype: map.pop(&('d' as u8)),
constraint: map.pop(&('n' as u8)), constraint: map.pop(&('n' as u8)),
file: map.pop(&('F' as u8)).unwrap(), file: map.pop(&('F' as u8)).unwrap(),
line: FromStr::from_str(map.pop(&('L' as u8)).unwrap()).unwrap(), line: FromStr::from_str(map.pop(&('L' as u8)).unwrap().as_slice()).unwrap(),
routine: map.pop(&('R' as u8)).unwrap() routine: map.pop(&('R' as u8)).unwrap()
} }
} }

View File

@ -323,9 +323,9 @@ pub struct PostgresNotification {
/// The process ID of the notifying backend process /// The process ID of the notifying backend process
pub pid: i32, pub pid: i32,
/// The name of the channel that the notify has been raised on /// The name of the channel that the notify has been raised on
pub channel: ~str, pub channel: StrBuf,
/// The "payload" string passed from the notifying process /// The "payload" string passed from the notifying process
pub payload: ~str, pub payload: StrBuf,
} }
/// An iterator over asynchronous notifications /// An iterator over asynchronous notifications
@ -1174,7 +1174,7 @@ impl<'conn> PostgresStatement<'conn> {
return Err(PgDbError(PostgresDbError::new(fields))); return Err(PgDbError(PostgresDbError::new(fields)));
} }
CommandComplete { tag } => { CommandComplete { tag } => {
let s = tag.split(' ').last().unwrap(); let s = tag.as_slice().split(' ').last().unwrap();
num = FromStr::from_str(s).unwrap_or(0); num = FromStr::from_str(s).unwrap_or(0);
break; break;
} }
@ -1230,7 +1230,7 @@ impl<'conn> PostgresStatement<'conn> {
#[deriving(Eq)] #[deriving(Eq)]
pub struct ResultDescription { pub struct ResultDescription {
/// The name of the column /// The name of the column
pub name: ~str, pub name: StrBuf,
/// The type of the data in the column /// The type of the data in the column
pub ty: PostgresType pub ty: PostgresType
} }

View File

@ -24,30 +24,30 @@ pub enum BackendMessage {
BindComplete, BindComplete,
CloseComplete, CloseComplete,
CommandComplete { CommandComplete {
pub tag: ~str pub tag: StrBuf,
}, },
DataRow { DataRow {
pub row: Vec<Option<Vec<u8>>> pub row: Vec<Option<Vec<u8>>>
}, },
EmptyQueryResponse, EmptyQueryResponse,
ErrorResponse { ErrorResponse {
pub fields: Vec<(u8, ~str)> pub fields: Vec<(u8, StrBuf)>
}, },
NoData, NoData,
NoticeResponse { NoticeResponse {
pub fields: Vec<(u8, ~str)> pub fields: Vec<(u8, StrBuf)>
}, },
NotificationResponse { NotificationResponse {
pub pid: i32, pub pid: i32,
pub channel: ~str, pub channel: StrBuf,
pub payload: ~str pub payload: StrBuf,
}, },
ParameterDescription { ParameterDescription {
pub types: Vec<Oid> pub types: Vec<Oid>
}, },
ParameterStatus { ParameterStatus {
pub parameter: ~str, pub parameter: StrBuf,
pub value: ~str pub value: StrBuf,
}, },
ParseComplete, ParseComplete,
PortalSuspended, PortalSuspended,
@ -60,7 +60,7 @@ pub enum BackendMessage {
} }
pub struct RowDescriptionEntry { pub struct RowDescriptionEntry {
pub name: ~str, pub name: StrBuf,
pub table_oid: Oid, pub table_oid: Oid,
pub column_id: i16, pub column_id: i16,
pub type_oid: Oid, pub type_oid: Oid,
@ -237,14 +237,14 @@ impl<W: Writer> WriteMessage for W {
#[doc(hidden)] #[doc(hidden)]
trait ReadCStr { trait ReadCStr {
fn read_cstr(&mut self) -> IoResult<~str>; fn read_cstr(&mut self) -> IoResult<StrBuf>;
} }
impl<R: Buffer> ReadCStr for R { impl<R: Buffer> ReadCStr for R {
fn read_cstr(&mut self) -> IoResult<~str> { fn read_cstr(&mut self) -> IoResult<StrBuf> {
let mut buf = try!(self.read_until(0)); let mut buf = try!(self.read_until(0));
buf.pop(); buf.pop();
Ok(StrBuf::from_utf8(buf).unwrap().into_owned()) Ok(StrBuf::from_utf8(buf).unwrap())
} }
} }
@ -294,7 +294,7 @@ impl<R: Reader> ReadMessage for R {
} }
} }
fn read_fields(buf: &mut MemReader) -> IoResult<Vec<(u8, ~str)>> { fn read_fields(buf: &mut MemReader) -> IoResult<Vec<(u8, StrBuf)>> {
let mut fields = Vec::new(); let mut fields = Vec::new();
loop { loop {
let ty = try!(buf.read_u8()); let ty = try!(buf.read_u8());

View File

@ -365,8 +365,8 @@ fn test_result_descriptions() {
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
let stmt = or_fail!(conn.prepare("SELECT 1::INT as a, 'hi'::VARCHAR as b")); let stmt = or_fail!(conn.prepare("SELECT 1::INT as a, 'hi'::VARCHAR as b"));
assert!(stmt.result_descriptions() == assert!(stmt.result_descriptions() ==
[ResultDescription { name: "a".to_owned(), ty: PgInt4}, [ResultDescription { name: "a".to_strbuf(), ty: PgInt4},
ResultDescription { name: "b".to_owned(), ty: PgVarchar}]); ResultDescription { name: "b".to_strbuf(), ty: PgVarchar}]);
} }
#[test] #[test]
@ -869,21 +869,21 @@ fn test_notification_iterator_some() {
check_notification(PostgresNotification { check_notification(PostgresNotification {
pid: 0, pid: 0,
channel: "test_notification_iterator_one_channel".to_owned(), channel: "test_notification_iterator_one_channel".to_strbuf(),
payload: "hello".to_owned() payload: "hello".to_strbuf()
}, it.next()); }, it.next());
check_notification(PostgresNotification { check_notification(PostgresNotification {
pid: 0, pid: 0,
channel: "test_notification_iterator_one_channel2".to_owned(), channel: "test_notification_iterator_one_channel2".to_strbuf(),
payload: "world".to_owned() payload: "world".to_strbuf()
}, it.next()); }, it.next());
assert!(it.next().is_none()); assert!(it.next().is_none());
or_fail!(conn.execute("NOTIFY test_notification_iterator_one_channel, '!'", [])); or_fail!(conn.execute("NOTIFY test_notification_iterator_one_channel, '!'", []));
check_notification(PostgresNotification { check_notification(PostgresNotification {
pid: 0, pid: 0,
channel: "test_notification_iterator_one_channel".to_owned(), channel: "test_notification_iterator_one_channel".to_strbuf(),
payload: "!".to_owned() payload: "!".to_strbuf()
}, it.next()); }, it.next());
assert!(it.next().is_none()); assert!(it.next().is_none());
} }