Skip to content

Commit

Permalink
Use Display instead of ToString in Rust generators (#18633)
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-garcia committed May 12, 2024
1 parent 365fcd3 commit 9704246
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ pub enum {{{classname}}} {
{{/enumVars}}{{/allowableValues}}
}

impl ToString for {{{classname}}} {
fn to_string(&self) -> String {
impl std::fmt::Display for {{{classname}}} {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
{{#allowableValues}}
{{#enumVars}}
Self::{{{name}}} => String::from("{{{value}}}"),
Self::{{{name}}} => write!(f, "{{{value}}}"),
{{/enumVars}}
{{/allowableValues}}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ pub enum Color {

}

impl ToString for Color {
fn to_string(&self) -> String {
impl std::fmt::Display for Color {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Red => String::from("RED"),
Self::Green => String::from("GREEN"),
Self::Blue => String::from("BLUE"),
Self::Red => write!(f, "RED"),
Self::Green => write!(f, "GREEN"),
Self::Blue => write!(f, "BLUE"),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ pub enum FruitType {

}

impl ToString for FruitType {
fn to_string(&self) -> String {
impl std::fmt::Display for FruitType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Apple => String::from("APPLE"),
Self::Banana => String::from("BANANA"),
Self::Apple => write!(f, "APPLE"),
Self::Banana => write!(f, "BANANA"),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ pub enum Color {

}

impl ToString for Color {
fn to_string(&self) -> String {
impl std::fmt::Display for Color {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Red => String::from("RED"),
Self::Green => String::from("GREEN"),
Self::Blue => String::from("BLUE"),
Self::Red => write!(f, "RED"),
Self::Green => write!(f, "GREEN"),
Self::Blue => write!(f, "BLUE"),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ pub enum FruitType {

}

impl ToString for FruitType {
fn to_string(&self) -> String {
impl std::fmt::Display for FruitType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Apple => String::from("APPLE"),
Self::Banana => String::from("BANANA"),
Self::Apple => write!(f, "APPLE"),
Self::Banana => write!(f, "BANANA"),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions samples/client/petstore/rust/hyper/petstore/src/models/baz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ pub enum Baz {

}

impl ToString for Baz {
fn to_string(&self) -> String {
impl std::fmt::Display for Baz {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::A => String::from("A"),
Self::B => String::from("B"),
Self::Empty => String::from(""),
Self::A => write!(f, "A"),
Self::B => write!(f, "B"),
Self::Empty => write!(f, ""),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ pub enum Baz {

}

impl ToString for Baz {
fn to_string(&self) -> String {
impl std::fmt::Display for Baz {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::A => String::from("A"),
Self::B => String::from("B"),
Self::Empty => String::from(""),
Self::A => write!(f, "A"),
Self::B => write!(f, "B"),
Self::Empty => write!(f, ""),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ pub enum Baz {

}

impl ToString for Baz {
fn to_string(&self) -> String {
impl std::fmt::Display for Baz {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::A => String::from("A"),
Self::B => String::from("B"),
Self::Empty => String::from(""),
Self::A => write!(f, "A"),
Self::B => write!(f, "B"),
Self::Empty => write!(f, ""),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ pub enum Baz {

}

impl ToString for Baz {
fn to_string(&self) -> String {
impl std::fmt::Display for Baz {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::A => String::from("A"),
Self::B => String::from("B"),
Self::Empty => String::from(""),
Self::A => write!(f, "A"),
Self::B => write!(f, "B"),
Self::Empty => write!(f, ""),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ pub enum Baz {

}

impl ToString for Baz {
fn to_string(&self) -> String {
impl std::fmt::Display for Baz {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::A => String::from("A"),
Self::B => String::from("B"),
Self::Empty => String::from(""),
Self::A => write!(f, "A"),
Self::B => write!(f, "B"),
Self::Empty => write!(f, ""),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions samples/client/petstore/rust/reqwest/petstore/src/models/baz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ pub enum Baz {

}

impl ToString for Baz {
fn to_string(&self) -> String {
impl std::fmt::Display for Baz {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::A => String::from("A"),
Self::B => String::from("B"),
Self::Empty => String::from(""),
Self::A => write!(f, "A"),
Self::B => write!(f, "B"),
Self::Empty => write!(f, ""),
}
}
}
Expand Down

0 comments on commit 9704246

Please sign in to comment.