Skip to content

Commit 9704246

Browse files
authored
Use Display instead of ToString in Rust generators (#18633)
1 parent 365fcd3 commit 9704246

File tree

11 files changed

+51
-51
lines changed

11 files changed

+51
-51
lines changed

modules/openapi-generator/src/main/resources/rust/model.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ pub enum {{{classname}}} {
2121
{{/enumVars}}{{/allowableValues}}
2222
}
2323

24-
impl ToString for {{{classname}}} {
25-
fn to_string(&self) -> String {
24+
impl std::fmt::Display for {{{classname}}} {
25+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2626
match self {
2727
{{#allowableValues}}
2828
{{#enumVars}}
29-
Self::{{{name}}} => String::from("{{{value}}}"),
29+
Self::{{{name}}} => write!(f, "{{{value}}}"),
3030
{{/enumVars}}
3131
{{/allowableValues}}
3232
}

samples/client/others/rust/hyper/api-with-ref-param/src/models/color.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ pub enum Color {
2323

2424
}
2525

26-
impl ToString for Color {
27-
fn to_string(&self) -> String {
26+
impl std::fmt::Display for Color {
27+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2828
match self {
29-
Self::Red => String::from("RED"),
30-
Self::Green => String::from("GREEN"),
31-
Self::Blue => String::from("BLUE"),
29+
Self::Red => write!(f, "RED"),
30+
Self::Green => write!(f, "GREEN"),
31+
Self::Blue => write!(f, "BLUE"),
3232
}
3333
}
3434
}

samples/client/others/rust/hyper/oneOf/src/models/fruit_type.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ pub enum FruitType {
2121

2222
}
2323

24-
impl ToString for FruitType {
25-
fn to_string(&self) -> String {
24+
impl std::fmt::Display for FruitType {
25+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2626
match self {
27-
Self::Apple => String::from("APPLE"),
28-
Self::Banana => String::from("BANANA"),
27+
Self::Apple => write!(f, "APPLE"),
28+
Self::Banana => write!(f, "BANANA"),
2929
}
3030
}
3131
}

samples/client/others/rust/reqwest/api-with-ref-param/src/models/color.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ pub enum Color {
2323

2424
}
2525

26-
impl ToString for Color {
27-
fn to_string(&self) -> String {
26+
impl std::fmt::Display for Color {
27+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2828
match self {
29-
Self::Red => String::from("RED"),
30-
Self::Green => String::from("GREEN"),
31-
Self::Blue => String::from("BLUE"),
29+
Self::Red => write!(f, "RED"),
30+
Self::Green => write!(f, "GREEN"),
31+
Self::Blue => write!(f, "BLUE"),
3232
}
3333
}
3434
}

samples/client/others/rust/reqwest/oneOf/src/models/fruit_type.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ pub enum FruitType {
2121

2222
}
2323

24-
impl ToString for FruitType {
25-
fn to_string(&self) -> String {
24+
impl std::fmt::Display for FruitType {
25+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2626
match self {
27-
Self::Apple => String::from("APPLE"),
28-
Self::Banana => String::from("BANANA"),
27+
Self::Apple => write!(f, "APPLE"),
28+
Self::Banana => write!(f, "BANANA"),
2929
}
3030
}
3131
}

samples/client/petstore/rust/hyper/petstore/src/models/baz.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pub enum Baz {
2424

2525
}
2626

27-
impl ToString for Baz {
28-
fn to_string(&self) -> String {
27+
impl std::fmt::Display for Baz {
28+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2929
match self {
30-
Self::A => String::from("A"),
31-
Self::B => String::from("B"),
32-
Self::Empty => String::from(""),
30+
Self::A => write!(f, "A"),
31+
Self::B => write!(f, "B"),
32+
Self::Empty => write!(f, ""),
3333
}
3434
}
3535
}

samples/client/petstore/rust/reqwest/petstore-async-middleware/src/models/baz.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pub enum Baz {
2424

2525
}
2626

27-
impl ToString for Baz {
28-
fn to_string(&self) -> String {
27+
impl std::fmt::Display for Baz {
28+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2929
match self {
30-
Self::A => String::from("A"),
31-
Self::B => String::from("B"),
32-
Self::Empty => String::from(""),
30+
Self::A => write!(f, "A"),
31+
Self::B => write!(f, "B"),
32+
Self::Empty => write!(f, ""),
3333
}
3434
}
3535
}

samples/client/petstore/rust/reqwest/petstore-async/src/models/baz.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pub enum Baz {
2424

2525
}
2626

27-
impl ToString for Baz {
28-
fn to_string(&self) -> String {
27+
impl std::fmt::Display for Baz {
28+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2929
match self {
30-
Self::A => String::from("A"),
31-
Self::B => String::from("B"),
32-
Self::Empty => String::from(""),
30+
Self::A => write!(f, "A"),
31+
Self::B => write!(f, "B"),
32+
Self::Empty => write!(f, ""),
3333
}
3434
}
3535
}

samples/client/petstore/rust/reqwest/petstore-avoid-box/src/models/baz.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pub enum Baz {
2424

2525
}
2626

27-
impl ToString for Baz {
28-
fn to_string(&self) -> String {
27+
impl std::fmt::Display for Baz {
28+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2929
match self {
30-
Self::A => String::from("A"),
31-
Self::B => String::from("B"),
32-
Self::Empty => String::from(""),
30+
Self::A => write!(f, "A"),
31+
Self::B => write!(f, "B"),
32+
Self::Empty => write!(f, ""),
3333
}
3434
}
3535
}

samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/baz.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pub enum Baz {
2424

2525
}
2626

27-
impl ToString for Baz {
28-
fn to_string(&self) -> String {
27+
impl std::fmt::Display for Baz {
28+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2929
match self {
30-
Self::A => String::from("A"),
31-
Self::B => String::from("B"),
32-
Self::Empty => String::from(""),
30+
Self::A => write!(f, "A"),
31+
Self::B => write!(f, "B"),
32+
Self::Empty => write!(f, ""),
3333
}
3434
}
3535
}

samples/client/petstore/rust/reqwest/petstore/src/models/baz.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pub enum Baz {
2424

2525
}
2626

27-
impl ToString for Baz {
28-
fn to_string(&self) -> String {
27+
impl std::fmt::Display for Baz {
28+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2929
match self {
30-
Self::A => String::from("A"),
31-
Self::B => String::from("B"),
32-
Self::Empty => String::from(""),
30+
Self::A => write!(f, "A"),
31+
Self::B => write!(f, "B"),
32+
Self::Empty => write!(f, ""),
3333
}
3434
}
3535
}

0 commit comments

Comments
 (0)