From 6b7627f8c9858303d85a97217ddf38abec9425d3 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Fri, 30 Mar 2018 09:48:18 -0700 Subject: [PATCH] Rename fs::read_string to read_to_string and stabilize --- src/librustc/util/common.rs | 3 ++- src/librustdoc/html/render.rs | 2 +- src/libstd/fs.rs | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 96b77d351e24c..6b896a889e300 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -244,7 +244,8 @@ fn get_resident() -> Option { 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::().ok()?; Some(npages * 4096) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index ff6cc56e5b4f5..d915bab7919c7 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -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}") { diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 3f0acfeea2262..3d8680cda9ff4 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -297,12 +297,12 @@ pub fn read>(path: P) -> io::Result> { /// use std::net::SocketAddr; /// /// fn main() -> Result<(), Box> { -/// 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>(path: P) -> io::Result { +#[stable(feature = "fs_read_write", since = "1.26.0")] +pub fn read_to_string>(path: P) -> io::Result { let mut file = File::open(path)?; let mut string = String::with_capacity(initial_buffer_size(&file)); file.read_to_string(&mut string)?; @@ -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); }