Skip to content

Commit

Permalink
Use f.write_str instead of formatting through write!(f, "{}", ...)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Nov 19, 2020
1 parent d403f2e commit 41c35b0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/codegen/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/codegen/trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/config/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
}
Expand Down

0 comments on commit 41c35b0

Please sign in to comment.