add a new File::append
constructor
#512
Labels
ACP-accepted
API Change Proposal is accepted (seconded with no objections)
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
T-libs-api
Proposal
Problem statement
Currently, when people want to write log file, he/she must write verbose & unreadable & error-prone code, such as:
The use of
File::options()....
also requires people thinking more about permissions & flags in detail:.open(true)
?).write(true)
?).create(true)
(error-prone)It requires people reading more docs and it's not easy to remember them all. Next time will do these again and again.
So, we need a small wrapper methods around
File::options().append(true).create(true).open("./log.txt")
, to make life better.Motivating examples or use cases
A common use case is open logging file and write new lines to it's end, the file may be exists or not:
the
File::append("./log.txt")
is very easy to use thanFile::options().append(true).create(true).open("./log.txt")
, and it's more readable (for review).Solution sketch
Add to
std::fs::File
:// open existing or create new file for append data.
// very useful when writing log files.
Alternatives
n/a
Links and related work
rust-lang/rust#134755
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: