diff --git a/modules/openapi-generator/src/main/resources/rust/model.mustache b/modules/openapi-generator/src/main/resources/rust/model.mustache index 79d3cda1c2b..7367124d7c9 100644 --- a/modules/openapi-generator/src/main/resources/rust/model.mustache +++ b/modules/openapi-generator/src/main/resources/rust/model.mustache @@ -27,15 +27,15 @@ pub enum {{{classname}}} { {{/enumVars}}{{/allowableValues}} } -impl ToString for {{{classname}}} { - fn to_string(&self) -> String { - match self { +impl std::fmt::Display for {{{classname}}} { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", match self { {{#allowableValues}} {{#enumVars}} - Self::{{{name}}} => String::from("{{{value}}}"), + Self::{{{name}}} => "{{{value}}}", {{/enumVars}} {{/allowableValues}} - } + }) } } {{/isInteger}} diff --git a/samples/client/petstore/rust/hyper/petstore/src/models/numeric_enum_testing.rs b/samples/client/petstore/rust/hyper/petstore/src/models/numeric_enum_testing.rs index 9b8f0cb0465..e3681aa6177 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/models/numeric_enum_testing.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/models/numeric_enum_testing.rs @@ -24,14 +24,14 @@ pub enum NumericEnumTesting { } -impl ToString for NumericEnumTesting { - fn to_string(&self) -> String { - match self { - Self::Variant0 => String::from("0"), - Self::Variant1 => String::from("1"), - Self::Variant2 => String::from("2"), - Self::Variant3 => String::from("3"), - } +impl std::fmt::Display for NumericEnumTesting { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", match self { + Self::Variant0 => "0", + Self::Variant1 => "1", + Self::Variant2 => "2", + Self::Variant3 => "3", + }) } } impl Default for NumericEnumTesting { diff --git a/samples/client/petstore/rust/hyper0x/petstore/src/models/numeric_enum_testing.rs b/samples/client/petstore/rust/hyper0x/petstore/src/models/numeric_enum_testing.rs index 9b8f0cb0465..e3681aa6177 100644 --- a/samples/client/petstore/rust/hyper0x/petstore/src/models/numeric_enum_testing.rs +++ b/samples/client/petstore/rust/hyper0x/petstore/src/models/numeric_enum_testing.rs @@ -24,14 +24,14 @@ pub enum NumericEnumTesting { } -impl ToString for NumericEnumTesting { - fn to_string(&self) -> String { - match self { - Self::Variant0 => String::from("0"), - Self::Variant1 => String::from("1"), - Self::Variant2 => String::from("2"), - Self::Variant3 => String::from("3"), - } +impl std::fmt::Display for NumericEnumTesting { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", match self { + Self::Variant0 => "0", + Self::Variant1 => "1", + Self::Variant2 => "2", + Self::Variant3 => "3", + }) } } impl Default for NumericEnumTesting { diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/models/numeric_enum_testing.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/models/numeric_enum_testing.rs index 9b8f0cb0465..e3681aa6177 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/models/numeric_enum_testing.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/models/numeric_enum_testing.rs @@ -24,14 +24,14 @@ pub enum NumericEnumTesting { } -impl ToString for NumericEnumTesting { - fn to_string(&self) -> String { - match self { - Self::Variant0 => String::from("0"), - Self::Variant1 => String::from("1"), - Self::Variant2 => String::from("2"), - Self::Variant3 => String::from("3"), - } +impl std::fmt::Display for NumericEnumTesting { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", match self { + Self::Variant0 => "0", + Self::Variant1 => "1", + Self::Variant2 => "2", + Self::Variant3 => "3", + }) } } impl Default for NumericEnumTesting { diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/models/numeric_enum_testing.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/models/numeric_enum_testing.rs index 9b8f0cb0465..e3681aa6177 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/models/numeric_enum_testing.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/models/numeric_enum_testing.rs @@ -24,14 +24,14 @@ pub enum NumericEnumTesting { } -impl ToString for NumericEnumTesting { - fn to_string(&self) -> String { - match self { - Self::Variant0 => String::from("0"), - Self::Variant1 => String::from("1"), - Self::Variant2 => String::from("2"), - Self::Variant3 => String::from("3"), - } +impl std::fmt::Display for NumericEnumTesting { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", match self { + Self::Variant0 => "0", + Self::Variant1 => "1", + Self::Variant2 => "2", + Self::Variant3 => "3", + }) } } impl Default for NumericEnumTesting { diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/models/numeric_enum_testing.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/models/numeric_enum_testing.rs index 9b8f0cb0465..e3681aa6177 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/models/numeric_enum_testing.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/models/numeric_enum_testing.rs @@ -24,14 +24,14 @@ pub enum NumericEnumTesting { } -impl ToString for NumericEnumTesting { - fn to_string(&self) -> String { - match self { - Self::Variant0 => String::from("0"), - Self::Variant1 => String::from("1"), - Self::Variant2 => String::from("2"), - Self::Variant3 => String::from("3"), - } +impl std::fmt::Display for NumericEnumTesting { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", match self { + Self::Variant0 => "0", + Self::Variant1 => "1", + Self::Variant2 => "2", + Self::Variant3 => "3", + }) } } impl Default for NumericEnumTesting { diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/numeric_enum_testing.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/numeric_enum_testing.rs index 9b8f0cb0465..e3681aa6177 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/numeric_enum_testing.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/numeric_enum_testing.rs @@ -24,14 +24,14 @@ pub enum NumericEnumTesting { } -impl ToString for NumericEnumTesting { - fn to_string(&self) -> String { - match self { - Self::Variant0 => String::from("0"), - Self::Variant1 => String::from("1"), - Self::Variant2 => String::from("2"), - Self::Variant3 => String::from("3"), - } +impl std::fmt::Display for NumericEnumTesting { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", match self { + Self::Variant0 => "0", + Self::Variant1 => "1", + Self::Variant2 => "2", + Self::Variant3 => "3", + }) } } impl Default for NumericEnumTesting { diff --git a/samples/client/petstore/rust/reqwest/petstore/src/models/numeric_enum_testing.rs b/samples/client/petstore/rust/reqwest/petstore/src/models/numeric_enum_testing.rs index 9b8f0cb0465..e3681aa6177 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/models/numeric_enum_testing.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/models/numeric_enum_testing.rs @@ -24,14 +24,14 @@ pub enum NumericEnumTesting { } -impl ToString for NumericEnumTesting { - fn to_string(&self) -> String { - match self { - Self::Variant0 => String::from("0"), - Self::Variant1 => String::from("1"), - Self::Variant2 => String::from("2"), - Self::Variant3 => String::from("3"), - } +impl std::fmt::Display for NumericEnumTesting { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", match self { + Self::Variant0 => "0", + Self::Variant1 => "1", + Self::Variant2 => "2", + Self::Variant3 => "3", + }) } } impl Default for NumericEnumTesting {