mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-30 04:56:25 +03:00
Auto merge of #130803 - cuviper:file-buffered, r=joshtriplett
Add `File` constructors that return files wrapped with a buffer In addition to the light convenience, these are intended to raise visibility that buffering is something you should consider when opening a file, since unbuffered I/O is a common performance footgun to Rust newcomers. ACP: https://github.com/rust-lang/libs-team/issues/446 Tracking Issue: #130804
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
use std::cell::RefCell;
|
||||
use std::ffi::OsString;
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufWriter, Write as _};
|
||||
use std::io::{self, Write as _};
|
||||
use std::iter::once;
|
||||
use std::marker::PhantomData;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
@@ -1020,8 +1020,7 @@ fn write_rendered_cci<T: CciPart, F>(
|
||||
for part in parts {
|
||||
template.append(part);
|
||||
}
|
||||
let file = try_err!(File::create(&path), &path);
|
||||
let mut file = BufWriter::new(file);
|
||||
let mut file = try_err!(File::create_buffered(&path), &path);
|
||||
try_err!(write!(file, "{template}"), &path);
|
||||
try_err!(file.flush(), &path);
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ fn after_krate(&mut self) -> Result<(), Error> {
|
||||
|
||||
self.serialize_and_write(
|
||||
output_crate,
|
||||
BufWriter::new(try_err!(File::create(&p), p)),
|
||||
try_err!(File::create_buffered(&p), p),
|
||||
&p.display().to_string(),
|
||||
)
|
||||
} else {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#![feature(rustc_private)]
|
||||
#![feature(assert_matches)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(file_buffered)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(impl_trait_in_assoc_type)]
|
||||
#![feature(iter_intersperse)]
|
||||
|
||||
Reference in New Issue
Block a user