Use Display instead of ToString in Rust generators (#18633)

This commit is contained in:
Daniel García 2024-05-12 05:06:03 +02:00 committed by GitHub
parent 365fcd3fb4
commit 970424678e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 51 additions and 51 deletions

View File

@ -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}}
}

View File

@ -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"),
}
}
}

View File

@ -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"),
}
}
}

View File

@ -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"),
}
}
}

View File

@ -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"),
}
}
}

View File

@ -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, ""),
}
}
}

View File

@ -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, ""),
}
}
}

View File

@ -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, ""),
}
}
}

View File

@ -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, ""),
}
}
}

View File

@ -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, ""),
}
}
}

View File

@ -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, ""),
}
}
}