From 78c633c097eef811dcffc913436188fbb865b2b6 Mon Sep 17 00:00:00 2001 From: Christoph Burgdorf Date: Fri, 13 Mar 2015 00:32:05 +0100 Subject: [PATCH 1/3] add RFC 841 to add back bufferless read_to_string/read_to_end methods --- text/0841-read_to_string_without_buffer.md | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 text/0841-read_to_string_without_buffer.md diff --git a/text/0841-read_to_string_without_buffer.md b/text/0841-read_to_string_without_buffer.md new file mode 100644 index 00000000000..a7ea76c3e37 --- /dev/null +++ b/text/0841-read_to_string_without_buffer.md @@ -0,0 +1,90 @@ +- Feature Name: read_to_string_without_buffer +- Start Date: 2015-03-13 +- RFC PR: https://github.com/rust-lang/rfcs/pull/970 +- Rust Issue: + +# Summary + +Add back `read_to_string` and `read_to_end` methods to the `Read` trait that +don't take a buffer. + +# Motivation + +While the `fn read_to_end(&mut self, buf: &mut Vec) -> Result<()>` and +`fn read_to_string(&mut self, buf: &mut String) -> Result<()>` APIs are more +efficient removing the APIs that don't require passing a buffer entirely comes +at with convenience loss in some situations. In particular if one want's to +implement a chaining API and doesn't care about efficiency. + +Today we either have to write this + +```rust +fn get_last_commit () -> String { + + let output = Command::new("git") + .arg("rev-parse") + .arg("HEAD") + .output() + .ok().expect("error invoking git rev-parse"); + + let encoded = String::from_utf8(output.stdout).ok().expect("error parsing output of git rev-parse"); + + encoded +} +``` + +Or this: + + +```rust +fn get_last_commit () -> String { + + Command::new("git") + .arg("rev-parse") + .arg("HEAD") + .output() + .map(|output| { + String::from_utf8(output.stdout).ok().expect("error reading into string") + }) + .ok().expect("error invoking git rev-parse") +} +``` + +But we'd like to be able to just write + +```rust +fn get_last_commit () -> String { + + Command::new("git") + .arg("rev-parse") + .arg("HEAD") + .spawn() + .ok().expect("error spawning process") + .stdout.read_to_string() + .ok().expect("error reading output") +} +``` + +This was possible before but since there is not such `read_to_string` API +anymore, it's currently impossible. + + +# Detailed design + +Add back methods with following signature + +`fn read_to_end(&mut self) -> Result>` + +`fn read_to_string(&mut self) -> Result` + +# Drawbacks + +Two more methods to maintain + +# Alternatives + +Don't do it and force users to use things like `map` for chaining + +# Unresolved questions + +None. From c433bae7f4c048094ffe01b1e49c8906437c5e6d Mon Sep 17 00:00:00 2001 From: Christoph Burgdorf Date: Fri, 13 Mar 2015 13:16:28 +0100 Subject: [PATCH 2/3] change proposed method names --- text/0841-read_to_string_without_buffer.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/text/0841-read_to_string_without_buffer.md b/text/0841-read_to_string_without_buffer.md index a7ea76c3e37..a5687e81052 100644 --- a/text/0841-read_to_string_without_buffer.md +++ b/text/0841-read_to_string_without_buffer.md @@ -5,8 +5,8 @@ # Summary -Add back `read_to_string` and `read_to_end` methods to the `Read` trait that -don't take a buffer. +Add `read_into_string` and `read_into_vec` methods to the `Read` trait that +act just like `read_to_string` and `read_to_end` but don't take a buffer. # Motivation @@ -60,7 +60,7 @@ fn get_last_commit () -> String { .arg("HEAD") .spawn() .ok().expect("error spawning process") - .stdout.read_to_string() + .stdout.read_into_string() .ok().expect("error reading output") } ``` @@ -73,9 +73,9 @@ anymore, it's currently impossible. Add back methods with following signature -`fn read_to_end(&mut self) -> Result>` +`fn read_into_vec(&mut self) -> Result>` -`fn read_to_string(&mut self) -> Result` +`fn read_into_string(&mut self) -> Result` # Drawbacks From 5f44f2c3f8e0c5a1a93d6b10707be5caa95f46bd Mon Sep 17 00:00:00 2001 From: Christoph Burgdorf Date: Fri, 13 Mar 2015 13:18:57 +0100 Subject: [PATCH 3/3] adds link to PR --- text/0841-read_to_string_without_buffer.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/0841-read_to_string_without_buffer.md b/text/0841-read_to_string_without_buffer.md index a5687e81052..126cf9d66dc 100644 --- a/text/0841-read_to_string_without_buffer.md +++ b/text/0841-read_to_string_without_buffer.md @@ -1,7 +1,7 @@ - Feature Name: read_to_string_without_buffer - Start Date: 2015-03-13 - RFC PR: https://github.com/rust-lang/rfcs/pull/970 -- Rust Issue: +- Rust Issue: https://github.com/rust-lang/rust/pull/23335 # Summary