Skip to content

Commit aea4f5a

Browse files
authored
replace unnecessary use of write! with Formatter::write_str (#840)
1 parent 386e313 commit aea4f5a

11 files changed

Lines changed: 2287 additions & 2112 deletions

typify-impl/src/type_entry.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,14 +816,16 @@ impl TypeEntry {
816816
impl ::std::fmt::Display for #type_name {
817817
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
818818
match *self {
819-
#(Self::#match_variants => write!(f, #match_strs),)*
819+
#(Self::#match_variants => f.write_str(#match_strs),)*
820820
}
821821
}
822822
}
823823
impl ::std::str::FromStr for #type_name {
824824
type Err = self::error::ConversionError;
825825

826-
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
826+
fn from_str(value: &str) ->
827+
::std::result::Result<Self, self::error::ConversionError>
828+
{
827829
match value {
828830
#(#match_strs => Ok(Self::#match_variants),)*
829831
_ => Err("invalid value".into()),

typify-impl/tests/generator.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ mod types {
196196
impl ::std::fmt::Display for StringEnum {
197197
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
198198
match *self {
199-
Self::One => write!(f, "One"),
200-
Self::Two => write!(f, "Two"),
201-
Self::BuckleMyShoe => write!(f, "BuckleMyShoe"),
199+
Self::One => f.write_str("One"),
200+
Self::Two => f.write_str("Two"),
201+
Self::BuckleMyShoe => f.write_str("BuckleMyShoe"),
202202
}
203203
}
204204
}

typify-impl/tests/github.out

Lines changed: 1140 additions & 1140 deletions
Large diffs are not rendered by default.

typify-impl/tests/vega.out

Lines changed: 886 additions & 886 deletions
Large diffs are not rendered by default.

typify/tests/schemas/extraneous-enum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ impl ::std::convert::From<&Self> for LetterBoxLetter {
111111
impl ::std::fmt::Display for LetterBoxLetter {
112112
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
113113
match *self {
114-
Self::A => write!(f, "a"),
115-
Self::B => write!(f, "b"),
114+
Self::A => f.write_str("a"),
115+
Self::B => f.write_str("b"),
116116
}
117117
}
118118
}

typify/tests/schemas/merged-schemas.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl ::std::convert::From<&Self> for JsonSuccessBaseResult {
364364
impl ::std::fmt::Display for JsonSuccessBaseResult {
365365
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
366366
match *self {
367-
Self::Success => write!(f, "success"),
367+
Self::Success => f.write_str("success"),
368368
}
369369
}
370370
}
@@ -436,7 +436,7 @@ impl ::std::convert::From<&Self> for JsonSuccessResult {
436436
impl ::std::fmt::Display for JsonSuccessResult {
437437
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
438438
match *self {
439-
Self::Success => write!(f, "success"),
439+
Self::Success => f.write_str("success"),
440440
}
441441
}
442442
}
@@ -952,7 +952,7 @@ impl ::std::convert::From<&Self> for UnchangedByMergeTag {
952952
impl ::std::fmt::Display for UnchangedByMergeTag {
953953
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
954954
match *self {
955-
Self::Something => write!(f, "something"),
955+
Self::Something => f.write_str("something"),
956956
}
957957
}
958958
}
@@ -1278,7 +1278,7 @@ impl ::std::convert::From<&Self> for Unsatisfiable3B {
12781278
impl ::std::fmt::Display for Unsatisfiable3B {
12791279
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
12801280
match *self {
1281-
Self::Bar => write!(f, "bar"),
1281+
Self::Bar => f.write_str("bar"),
12821282
}
12831283
}
12841284
}
@@ -1350,7 +1350,7 @@ impl ::std::convert::From<&Self> for Unsatisfiable3C {
13501350
impl ::std::fmt::Display for Unsatisfiable3C {
13511351
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
13521352
match *self {
1353-
Self::Foo => write!(f, "foo"),
1353+
Self::Foo => f.write_str("foo"),
13541354
}
13551355
}
13561356
}

0 commit comments

Comments
 (0)