libstd: Remove ~str from all libstd modules except fmt and str.
This commit is contained in:
@@ -76,7 +76,7 @@ Some examples of obvious things you might want to do
|
||||
|
||||
let path = Path::new("message.txt");
|
||||
let mut file = BufferedReader::new(File::open(&path));
|
||||
let lines: Vec<~str> = file.lines().map(|x| x.unwrap()).collect();
|
||||
let lines: Vec<StrBuf> = file.lines().map(|x| x.unwrap()).collect();
|
||||
```
|
||||
|
||||
* Make a simple TCP client connection and request
|
||||
@@ -228,6 +228,7 @@ use result::{Ok, Err, Result};
|
||||
use slice::{Vector, MutableVector, ImmutableVector};
|
||||
use str::{StrSlice, StrAllocating};
|
||||
use str;
|
||||
use strbuf::StrBuf;
|
||||
use uint;
|
||||
use vec::Vec;
|
||||
|
||||
@@ -292,7 +293,7 @@ pub struct IoError {
|
||||
/// A human-readable description about the error
|
||||
pub desc: &'static str,
|
||||
/// Detailed information about this error, not always available
|
||||
pub detail: Option<~str>
|
||||
pub detail: Option<StrBuf>
|
||||
}
|
||||
|
||||
impl IoError {
|
||||
@@ -364,7 +365,11 @@ impl IoError {
|
||||
IoError {
|
||||
kind: kind,
|
||||
desc: desc,
|
||||
detail: if detail {Some(os::error_string(errno))} else {None},
|
||||
detail: if detail {
|
||||
Some(os::error_string(errno))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,8 +495,10 @@ pub trait Reader {
|
||||
/// bytes are read.
|
||||
fn read_at_least(&mut self, min: uint, buf: &mut [u8]) -> IoResult<uint> {
|
||||
if min > buf.len() {
|
||||
return Err(IoError { detail: Some("the buffer is too short".to_owned()),
|
||||
..standard_error(InvalidInput) });
|
||||
return Err(IoError {
|
||||
detail: Some("the buffer is too short".to_strbuf()),
|
||||
..standard_error(InvalidInput)
|
||||
});
|
||||
}
|
||||
let mut read = 0;
|
||||
while read < min {
|
||||
@@ -556,8 +563,10 @@ pub trait Reader {
|
||||
/// bytes are read.
|
||||
fn push_at_least(&mut self, min: uint, len: uint, buf: &mut Vec<u8>) -> IoResult<uint> {
|
||||
if min > len {
|
||||
return Err(IoError { detail: Some("the buffer is too short".to_owned()),
|
||||
..standard_error(InvalidInput) });
|
||||
return Err(IoError {
|
||||
detail: Some("the buffer is too short".to_strbuf()),
|
||||
..standard_error(InvalidInput)
|
||||
});
|
||||
}
|
||||
|
||||
let start_len = buf.len();
|
||||
@@ -623,10 +632,10 @@ pub trait Reader {
|
||||
/// This function returns all of the same errors as `read_to_end` with an
|
||||
/// additional error if the reader's contents are not a valid sequence of
|
||||
/// UTF-8 bytes.
|
||||
fn read_to_str(&mut self) -> IoResult<~str> {
|
||||
fn read_to_str(&mut self) -> IoResult<StrBuf> {
|
||||
self.read_to_end().and_then(|s| {
|
||||
match str::from_utf8(s.as_slice()) {
|
||||
Some(s) => Ok(s.to_owned()),
|
||||
Some(s) => Ok(s.to_strbuf()),
|
||||
None => Err(standard_error(InvalidInput)),
|
||||
}
|
||||
})
|
||||
@@ -1235,8 +1244,8 @@ pub struct Lines<'r, T> {
|
||||
buffer: &'r mut T,
|
||||
}
|
||||
|
||||
impl<'r, T: Buffer> Iterator<IoResult<~str>> for Lines<'r, T> {
|
||||
fn next(&mut self) -> Option<IoResult<~str>> {
|
||||
impl<'r, T: Buffer> Iterator<IoResult<StrBuf>> for Lines<'r, T> {
|
||||
fn next(&mut self) -> Option<IoResult<StrBuf>> {
|
||||
match self.buffer.read_line() {
|
||||
Ok(x) => Some(Ok(x)),
|
||||
Err(IoError { kind: EndOfFile, ..}) => None,
|
||||
@@ -1321,10 +1330,10 @@ pub trait Buffer: Reader {
|
||||
///
|
||||
/// Additionally, this function can fail if the line of input read is not a
|
||||
/// valid UTF-8 sequence of bytes.
|
||||
fn read_line(&mut self) -> IoResult<~str> {
|
||||
fn read_line(&mut self) -> IoResult<StrBuf> {
|
||||
self.read_until('\n' as u8).and_then(|line|
|
||||
match str::from_utf8(line.as_slice()) {
|
||||
Some(s) => Ok(s.to_owned()),
|
||||
Some(s) => Ok(s.to_strbuf()),
|
||||
None => Err(standard_error(InvalidInput)),
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user