Skip to content

Commit

Permalink
Merge pull request #15 from golemcloud/fix-tostring-clippy
Browse files Browse the repository at this point in the history
Add allow attribute for new Rust version
  • Loading branch information
vigoo authored May 4, 2024
2 parents 6b67cf1 + 06761ed commit 7a591a1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use std::ops::Add;

#[derive(Clone, Debug)]
#[allow(dead_code)]
pub struct Error;

pub trait Printer<Context> {
Expand Down
25 changes: 15 additions & 10 deletions src/rust/model_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl RefCache {
fn serialize() -> RustPrinter {
rust_name("serde", "Serialize")
}

fn deserialize() -> RustPrinter {
rust_name("serde", "Deserialize")
}
Expand Down Expand Up @@ -316,12 +317,14 @@ fn extract_enum_case(
data_type: ref_type_name(reference, ref_cache)?,
})
} else {
Err(Error::unimplemented(
"Can't find model type reference in enum case schema.",
))
Err(Error::unimplemented(format!(
"Can't find model type reference in enum case schema {schema_name}.",
)))
}
}
_ => Err(Error::unimplemented("allOf schema expected for enum case")),
_ => Err(Error::unimplemented(format!(
"allOf schema expected for enum case in {schema_name}"
))),
}
}

Expand Down Expand Up @@ -415,25 +418,27 @@ pub fn model_gen(reference: &str, open_api: &OpenAPI, ref_cache: &mut RefCache)
.unwrap_or_else(unit);

#[rustfmt::skip]
let code = unit() +
let code = unit() +
derive_line() +
line(unit() + "pub enum " + &name + " {") +
indented(
cases
) +
line(unit() + "}") +
NewLine +
line(unit() + "#[allow(clippy::to_string_trait_impl)]") +
NewLine +
line(unit() + "impl ToString for " + &name + "{") +
indented(
line("fn to_string(&self) -> String {") +
indented(
line("match self {") +
indented(
match_cases
line("match self {") +
indented(
match_cases
) +
line("}")
) +
line("}")
) +
line("}")
) +
line("}");

Expand Down
1 change: 1 addition & 0 deletions src/rust/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl RustContext {
}
}

#[allow(clippy::to_string_trait_impl)]
impl ToString for RustContext {
#[allow(unstable_name_collisions)]
fn to_string(&self) -> String {
Expand Down
1 change: 1 addition & 0 deletions src/rust/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub enum IntFormat {
I64,
}

#[allow(clippy::to_string_trait_impl)]
impl ToString for IntFormat {
fn to_string(&self) -> String {
match self {
Expand Down

0 comments on commit 7a591a1

Please sign in to comment.