forked from loafle/openapi-generator-original
rust: Implement Display
instead of ToString
for enums (#19611)
Rust docs for `ToString` explicitly recommend implementing `Display`: > This trait is automatically implemented for any type which implements the Display trait. As such, ToString shouldn’t be implemented directly: Display should be implemented instead, and you get the ToString implementation for free. See: https://doc.rust-lang.org/std/string/trait.ToString.html See: https://github.com/Nitrokey/nethsm-sdk-rs/pull/33 Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
This commit is contained in:
parent
7d8eacc197
commit
5732e2758f
@ -27,15 +27,15 @@ pub enum {{{classname}}} {
|
|||||||
{{/enumVars}}{{/allowableValues}}
|
{{/enumVars}}{{/allowableValues}}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for {{{classname}}} {
|
impl std::fmt::Display for {{{classname}}} {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
write!(f, "{}", match self {
|
||||||
{{#allowableValues}}
|
{{#allowableValues}}
|
||||||
{{#enumVars}}
|
{{#enumVars}}
|
||||||
Self::{{{name}}} => String::from("{{{value}}}"),
|
Self::{{{name}}} => "{{{value}}}",
|
||||||
{{/enumVars}}
|
{{/enumVars}}
|
||||||
{{/allowableValues}}
|
{{/allowableValues}}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/isInteger}}
|
{{/isInteger}}
|
||||||
|
@ -24,14 +24,14 @@ pub enum NumericEnumTesting {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for NumericEnumTesting {
|
impl std::fmt::Display for NumericEnumTesting {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
write!(f, "{}", match self {
|
||||||
Self::Variant0 => String::from("0"),
|
Self::Variant0 => "0",
|
||||||
Self::Variant1 => String::from("1"),
|
Self::Variant1 => "1",
|
||||||
Self::Variant2 => String::from("2"),
|
Self::Variant2 => "2",
|
||||||
Self::Variant3 => String::from("3"),
|
Self::Variant3 => "3",
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Default for NumericEnumTesting {
|
impl Default for NumericEnumTesting {
|
||||||
|
@ -24,14 +24,14 @@ pub enum NumericEnumTesting {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for NumericEnumTesting {
|
impl std::fmt::Display for NumericEnumTesting {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
write!(f, "{}", match self {
|
||||||
Self::Variant0 => String::from("0"),
|
Self::Variant0 => "0",
|
||||||
Self::Variant1 => String::from("1"),
|
Self::Variant1 => "1",
|
||||||
Self::Variant2 => String::from("2"),
|
Self::Variant2 => "2",
|
||||||
Self::Variant3 => String::from("3"),
|
Self::Variant3 => "3",
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Default for NumericEnumTesting {
|
impl Default for NumericEnumTesting {
|
||||||
|
@ -24,14 +24,14 @@ pub enum NumericEnumTesting {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for NumericEnumTesting {
|
impl std::fmt::Display for NumericEnumTesting {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
write!(f, "{}", match self {
|
||||||
Self::Variant0 => String::from("0"),
|
Self::Variant0 => "0",
|
||||||
Self::Variant1 => String::from("1"),
|
Self::Variant1 => "1",
|
||||||
Self::Variant2 => String::from("2"),
|
Self::Variant2 => "2",
|
||||||
Self::Variant3 => String::from("3"),
|
Self::Variant3 => "3",
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Default for NumericEnumTesting {
|
impl Default for NumericEnumTesting {
|
||||||
|
@ -24,14 +24,14 @@ pub enum NumericEnumTesting {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for NumericEnumTesting {
|
impl std::fmt::Display for NumericEnumTesting {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
write!(f, "{}", match self {
|
||||||
Self::Variant0 => String::from("0"),
|
Self::Variant0 => "0",
|
||||||
Self::Variant1 => String::from("1"),
|
Self::Variant1 => "1",
|
||||||
Self::Variant2 => String::from("2"),
|
Self::Variant2 => "2",
|
||||||
Self::Variant3 => String::from("3"),
|
Self::Variant3 => "3",
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Default for NumericEnumTesting {
|
impl Default for NumericEnumTesting {
|
||||||
|
@ -24,14 +24,14 @@ pub enum NumericEnumTesting {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for NumericEnumTesting {
|
impl std::fmt::Display for NumericEnumTesting {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
write!(f, "{}", match self {
|
||||||
Self::Variant0 => String::from("0"),
|
Self::Variant0 => "0",
|
||||||
Self::Variant1 => String::from("1"),
|
Self::Variant1 => "1",
|
||||||
Self::Variant2 => String::from("2"),
|
Self::Variant2 => "2",
|
||||||
Self::Variant3 => String::from("3"),
|
Self::Variant3 => "3",
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Default for NumericEnumTesting {
|
impl Default for NumericEnumTesting {
|
||||||
|
@ -24,14 +24,14 @@ pub enum NumericEnumTesting {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for NumericEnumTesting {
|
impl std::fmt::Display for NumericEnumTesting {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
write!(f, "{}", match self {
|
||||||
Self::Variant0 => String::from("0"),
|
Self::Variant0 => "0",
|
||||||
Self::Variant1 => String::from("1"),
|
Self::Variant1 => "1",
|
||||||
Self::Variant2 => String::from("2"),
|
Self::Variant2 => "2",
|
||||||
Self::Variant3 => String::from("3"),
|
Self::Variant3 => "3",
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Default for NumericEnumTesting {
|
impl Default for NumericEnumTesting {
|
||||||
|
@ -24,14 +24,14 @@ pub enum NumericEnumTesting {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for NumericEnumTesting {
|
impl std::fmt::Display for NumericEnumTesting {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
write!(f, "{}", match self {
|
||||||
Self::Variant0 => String::from("0"),
|
Self::Variant0 => "0",
|
||||||
Self::Variant1 => String::from("1"),
|
Self::Variant1 => "1",
|
||||||
Self::Variant2 => String::from("2"),
|
Self::Variant2 => "2",
|
||||||
Self::Variant3 => String::from("3"),
|
Self::Variant3 => "3",
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Default for NumericEnumTesting {
|
impl Default for NumericEnumTesting {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user