From 970424678e915bf6b8a9c49d410d228144289f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Sun, 12 May 2024 05:06:03 +0200 Subject: [PATCH] Use Display instead of ToString in Rust generators (#18633) --- .../src/main/resources/rust/model.mustache | 6 +++--- .../rust/hyper/api-with-ref-param/src/models/color.rs | 10 +++++----- .../others/rust/hyper/oneOf/src/models/fruit_type.rs | 8 ++++---- .../reqwest/api-with-ref-param/src/models/color.rs | 10 +++++----- .../others/rust/reqwest/oneOf/src/models/fruit_type.rs | 8 ++++---- .../petstore/rust/hyper/petstore/src/models/baz.rs | 10 +++++----- .../petstore-async-middleware/src/models/baz.rs | 10 +++++----- .../rust/reqwest/petstore-async/src/models/baz.rs | 10 +++++----- .../rust/reqwest/petstore-avoid-box/src/models/baz.rs | 10 +++++----- .../reqwest/petstore-awsv4signature/src/models/baz.rs | 10 +++++----- .../petstore/rust/reqwest/petstore/src/models/baz.rs | 10 +++++----- 11 files changed, 51 insertions(+), 51 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust/model.mustache b/modules/openapi-generator/src/main/resources/rust/model.mustache index 94fcdf097eae..dd7ac5a1cdf6 100644 --- a/modules/openapi-generator/src/main/resources/rust/model.mustache +++ b/modules/openapi-generator/src/main/resources/rust/model.mustache @@ -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}} } diff --git a/samples/client/others/rust/hyper/api-with-ref-param/src/models/color.rs b/samples/client/others/rust/hyper/api-with-ref-param/src/models/color.rs index 26b274a562ee..7fcd2768c209 100644 --- a/samples/client/others/rust/hyper/api-with-ref-param/src/models/color.rs +++ b/samples/client/others/rust/hyper/api-with-ref-param/src/models/color.rs @@ -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"), } } } diff --git a/samples/client/others/rust/hyper/oneOf/src/models/fruit_type.rs b/samples/client/others/rust/hyper/oneOf/src/models/fruit_type.rs index e24e1de32119..6548af28e3f8 100644 --- a/samples/client/others/rust/hyper/oneOf/src/models/fruit_type.rs +++ b/samples/client/others/rust/hyper/oneOf/src/models/fruit_type.rs @@ -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"), } } } diff --git a/samples/client/others/rust/reqwest/api-with-ref-param/src/models/color.rs b/samples/client/others/rust/reqwest/api-with-ref-param/src/models/color.rs index 26b274a562ee..7fcd2768c209 100644 --- a/samples/client/others/rust/reqwest/api-with-ref-param/src/models/color.rs +++ b/samples/client/others/rust/reqwest/api-with-ref-param/src/models/color.rs @@ -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"), } } } diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/fruit_type.rs b/samples/client/others/rust/reqwest/oneOf/src/models/fruit_type.rs index e24e1de32119..6548af28e3f8 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/models/fruit_type.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/models/fruit_type.rs @@ -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"), } } } diff --git a/samples/client/petstore/rust/hyper/petstore/src/models/baz.rs b/samples/client/petstore/rust/hyper/petstore/src/models/baz.rs index dcf25d8465a3..17b42c0bd4f0 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/models/baz.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/models/baz.rs @@ -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, ""), } } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/models/baz.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/models/baz.rs index dcf25d8465a3..17b42c0bd4f0 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/models/baz.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/models/baz.rs @@ -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, ""), } } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/models/baz.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/models/baz.rs index dcf25d8465a3..17b42c0bd4f0 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/models/baz.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/models/baz.rs @@ -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, ""), } } } diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/models/baz.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/models/baz.rs index dcf25d8465a3..17b42c0bd4f0 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/models/baz.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/models/baz.rs @@ -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, ""), } } } diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/baz.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/baz.rs index dcf25d8465a3..17b42c0bd4f0 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/baz.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/baz.rs @@ -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, ""), } } } diff --git a/samples/client/petstore/rust/reqwest/petstore/src/models/baz.rs b/samples/client/petstore/rust/reqwest/petstore/src/models/baz.rs index dcf25d8465a3..17b42c0bd4f0 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/models/baz.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/models/baz.rs @@ -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, ""), } } }