From 41c35b05155ef0aac17da8eba246956e3be0a268 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Thu, 19 Nov 2020 16:27:53 +0100 Subject: [PATCH] Use f.write_str instead of formatting through write!(f, "{}", ...) --- src/codegen/object.rs | 2 +- src/codegen/trait_impls.rs | 11 ++++++----- src/config/ident.rs | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/codegen/object.rs b/src/codegen/object.rs index 208c9aeec..3c071cfde 100644 --- a/src/codegen/object.rs +++ b/src/codegen/object.rs @@ -139,7 +139,7 @@ pub fn generate( writeln!( w, "\tfn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {{\n\ - \t\twrite!(f, \"{}\")\n\ + \t\tf.write_str(\"{}\")\n\ \t}}\n\ }}", analysis.name diff --git a/src/codegen/trait_impls.rs b/src/codegen/trait_impls.rs index 97475caf6..87eafac96 100644 --- a/src/codegen/trait_impls.rs +++ b/src/codegen/trait_impls.rs @@ -84,11 +84,12 @@ fn generate_display( let call = generate_call(&func.name, &[], trait_name); let body = if let Mode::Throws(_) = func.outs.mode { format!( - "if let Ok(val) = {} {{ - write!(f, \"{{}}\", val) - }} else {{ - Err(fmt::Error) - }}", + "\ + if let Ok(val) = {} {{ + f.write_str(val) + }} else {{ + Err(fmt::Error) + }}", call ) } else { diff --git a/src/config/ident.rs b/src/config/ident.rs index 831e6a3cd..73c8bb9ca 100644 --- a/src/config/ident.rs +++ b/src/config/ident.rs @@ -13,9 +13,9 @@ pub enum Ident { impl fmt::Display for Ident { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - Ident::Name(ref name) => write!(f, "{}", name), + Ident::Name(ref name) => f.write_str(name), // TODO: maybe store the regex string to display it here? - Ident::Pattern(_) => write!(f, "Regex"), + Ident::Pattern(_) => f.write_str("Regex"), } } }