Skip to content

Commit 9ceaa56

Browse files
committed
Auto merge of #49522 - mbrubeck:fs_read, r=SimonSapin
Rename fs::read_string to read_to_string and stabilize As approved in #46588 (comment) Closes #46588.
2 parents 2b49944 + 6b7627f commit 9ceaa56

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/librustc/util/common.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ fn get_resident() -> Option<usize> {
244244
use std::fs;
245245

246246
let field = 1;
247-
let contents = fs::read_string("/proc/self/statm").ok()?;
247+
let contents = fs::read("/proc/self/statm").ok()?;
248+
let contents = String::from_utf8(contents).ok()?;
248249
let s = contents.split_whitespace().nth(field)?;
249250
let npages = s.parse::<usize>().ok()?;
250251
Some(npages * 4096)

src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ impl<'a> SourceCollector<'a> {
10671067
return Ok(());
10681068
}
10691069

1070-
let contents = fs::read_string(&p)?;
1070+
let contents = fs::read_to_string(&p)?;
10711071

10721072
// Remove the utf-8 BOM if any
10731073
let contents = if contents.starts_with("\u{feff}") {

src/libstd/fs.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,12 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
297297
/// use std::net::SocketAddr;
298298
///
299299
/// fn main() -> Result<(), Box<std::error::Error + 'static>> {
300-
/// let foo: SocketAddr = fs::read_string("address.txt")?.parse()?;
300+
/// let foo: SocketAddr = fs::read_to_string("address.txt")?.parse()?;
301301
/// Ok(())
302302
/// }
303303
/// ```
304-
#[unstable(feature = "fs_read_write", issue = "46588")]
305-
pub fn read_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
304+
#[stable(feature = "fs_read_write", since = "1.26.0")]
305+
pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
306306
let mut file = File::open(path)?;
307307
let mut string = String::with_capacity(initial_buffer_size(&file));
308308
file.read_to_string(&mut string)?;
@@ -3122,12 +3122,12 @@ mod tests {
31223122
assert!(v == &bytes[..]);
31233123

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

31283128
let s = "𐁁𐀓𐀠𐀴𐀍";
31293129
check!(fs::write(&tmpdir.join("utf8"), s.as_bytes()));
3130-
let string = check!(fs::read_string(&tmpdir.join("utf8")));
3130+
let string = check!(fs::read_to_string(&tmpdir.join("utf8")));
31313131
assert_eq!(string, s);
31323132
}
31333133

0 commit comments

Comments
 (0)