Skip to content

Commit

Permalink
Reuse formatter instance
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Feb 2, 2021
1 parent d62fc87 commit d8230db
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions rmpv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl Display for Utf8String {
#[cold]
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self.s {
Ok(ref s) => write!(fmt, "\"{}\"", s),
Ok(ref s) => Debug::fmt(&s, fmt),
Err(ref err) => Debug::fmt(&err.0, fmt),
}
}
Expand Down Expand Up @@ -399,7 +399,7 @@ impl<'a> Display for Utf8StringRef<'a> {
#[cold]
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self.s {
Ok(ref s) => write!(fmt, "\"{}\"", s),
Ok(ref s) => Debug::fmt(&s, fmt),
Err(ref err) => Debug::fmt(&err.0, fmt),
}
}
Expand Down Expand Up @@ -1186,13 +1186,13 @@ impl Display for Value {
#[cold]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match *self {
Value::Nil => Display::fmt("nil", f),
Value::Boolean(val) => write!(f, "{}", val),
Value::Integer(ref val) => write!(f, "{}", val),
Value::F32(val) => write!(f, "{}", val),
Value::F64(val) => write!(f, "{}", val),
Value::String(ref val) => write!(f, "{}", val),
Value::Binary(ref val) => write!(f, "{:?}", val),
Value::Nil => f.write_str("nil"),
Value::Boolean(val) => Display::fmt(&val, f),
Value::Integer(ref val) => Display::fmt(&val, f),
Value::F32(val) => Display::fmt(&val, f),
Value::F64(val) => Display::fmt(&val, f),
Value::String(ref val) => Display::fmt(&val, f),
Value::Binary(ref val) => Debug::fmt(&val, f),
Value::Array(ref vec) => {
// TODO: This can be slower than naive implementation. Need benchmarks for more
// information.
Expand Down Expand Up @@ -1537,12 +1537,12 @@ impl<'a> Display for ValueRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match *self {
ValueRef::Nil => write!(f, "nil"),
ValueRef::Boolean(val) => write!(f, "{}", val),
ValueRef::Integer(ref val) => write!(f, "{}", val),
ValueRef::F32(val) => write!(f, "{}", val),
ValueRef::F64(val) => write!(f, "{}", val),
ValueRef::String(ref val) => write!(f, "{}", val),
ValueRef::Binary(ref val) => write!(f, "{:?}", val),
ValueRef::Boolean(val) => Display::fmt(&val, f),
ValueRef::Integer(ref val) => Display::fmt(&val, f),
ValueRef::F32(val) => Display::fmt(&val, f),
ValueRef::F64(val) => Display::fmt(&val, f),
ValueRef::String(ref val) => Display::fmt(&val, f),
ValueRef::Binary(ref val) => Debug::fmt(&val, f),
ValueRef::Array(ref vec) => {
let res = vec.iter()
.map(|val| format!("{}", val))
Expand Down

0 comments on commit d8230db

Please sign in to comment.