Pass &str to write_string_fragment

This commit is contained in:
David Tolnay 2017-02-27 20:19:44 -08:00
parent e8a06ef631
commit ecdc3d5ab1
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -956,10 +956,10 @@ pub trait Formatter {
/// Writes a string fragment that doesn't need any escaping to the
/// specified writer.
#[inline]
fn write_string_fragment<W: ?Sized>(&mut self, writer: &mut W, fragment: &[u8]) -> Result<()>
fn write_string_fragment<W: ?Sized>(&mut self, writer: &mut W, fragment: &str) -> Result<()>
where W: io::Write
{
writer.write_all(fragment).map_err(From::from)
writer.write_all(fragment.as_bytes()).map_err(From::from)
}
/// Writes a character escape code to the specified writer.
@ -1248,7 +1248,7 @@ fn format_escaped_str_contents<W: ?Sized, F: ?Sized>(writer: &mut W,
}
if start < i {
try!(formatter.write_string_fragment(writer, &bytes[start..i]));
try!(formatter.write_string_fragment(writer, &value[start..i]));
}
let char_escape = CharEscape::from_escape_table(escape, byte);
@ -1258,7 +1258,7 @@ fn format_escaped_str_contents<W: ?Sized, F: ?Sized>(writer: &mut W,
}
if start != bytes.len() {
try!(formatter.write_string_fragment(writer, &bytes[start..]));
try!(formatter.write_string_fragment(writer, &value[start..]));
}
Ok(())