Skip to content

Commit

Permalink
Rename fs::read_string to read_to_string and stabilize
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrubeck committed Mar 30, 2018
1 parent 4379c86 commit 6b7627f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/librustc/util/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ fn get_resident() -> Option<usize> {
use std::fs;

let field = 1;
let contents = fs::read_string("/proc/self/statm").ok()?;
let contents = fs::read("/proc/self/statm").ok()?;
let contents = String::from_utf8(contents).ok()?;
let s = contents.split_whitespace().nth(field)?;
let npages = s.parse::<usize>().ok()?;
Some(npages * 4096)
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ impl<'a> SourceCollector<'a> {
return Ok(());
}

let contents = fs::read_string(&p)?;
let contents = fs::read_to_string(&p)?;

// Remove the utf-8 BOM if any
let contents = if contents.starts_with("\u{feff}") {
Expand Down
10 changes: 5 additions & 5 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
/// use std::net::SocketAddr;
///
/// fn main() -> Result<(), Box<std::error::Error + 'static>> {
/// let foo: SocketAddr = fs::read_string("address.txt")?.parse()?;
/// let foo: SocketAddr = fs::read_to_string("address.txt")?.parse()?;
/// Ok(())
/// }
/// ```
#[unstable(feature = "fs_read_write", issue = "46588")]
pub fn read_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
#[stable(feature = "fs_read_write", since = "1.26.0")]
pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
let mut file = File::open(path)?;
let mut string = String::with_capacity(initial_buffer_size(&file));
file.read_to_string(&mut string)?;
Expand Down Expand Up @@ -3122,12 +3122,12 @@ mod tests {
assert!(v == &bytes[..]);

check!(fs::write(&tmpdir.join("not-utf8"), &[0xFF]));
error_contains!(fs::read_string(&tmpdir.join("not-utf8")),
error_contains!(fs::read_to_string(&tmpdir.join("not-utf8")),
"stream did not contain valid UTF-8");

let s = "𐁁𐀓𐀠𐀴𐀍";
check!(fs::write(&tmpdir.join("utf8"), s.as_bytes()));
let string = check!(fs::read_string(&tmpdir.join("utf8")));
let string = check!(fs::read_to_string(&tmpdir.join("utf8")));
assert_eq!(string, s);
}

Expand Down

0 comments on commit 6b7627f

Please sign in to comment.