Skip to content

Commit 0b73ff6

Browse files
authored
refactor: use String buffer for StringOutput (#739)
* refactor: use String buffer for StringOutput * fix: lint * fix: lint
1 parent b1b39cd commit 0b73ff6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/output.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,29 @@ impl<W: Write> WriteOutput<W> {
4242
}
4343

4444
pub struct StringOutput {
45-
buf: Vec<u8>,
45+
buf: String,
4646
}
4747

4848
impl Output for StringOutput {
4949
fn write(&mut self, seg: &str) -> Result<(), IOError> {
50-
self.buf.extend_from_slice(seg.as_bytes());
50+
self.buf.push_str(seg);
5151
Ok(())
5252
}
5353

5454
fn write_fmt(&mut self, args: std::fmt::Arguments<'_>) -> Result<(), IOError> {
55-
self.buf.write_fmt(args)
55+
std::fmt::Write::write_fmt(&mut self.buf, args).map_err(IOError::other)
5656
}
5757
}
5858

5959
impl StringOutput {
6060
pub fn new() -> StringOutput {
6161
StringOutput {
62-
buf: Vec::with_capacity(8 * 1024),
62+
buf: String::with_capacity(8 * 1024),
6363
}
6464
}
6565

6666
pub fn into_string(self) -> Result<String, FromUtf8Error> {
67-
String::from_utf8(self.buf)
67+
Ok(self.buf)
6868
}
6969
}
7070

0 commit comments

Comments
 (0)