Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoo committed Oct 30, 2024
1 parent c9016b5 commit 08bea85
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
66 changes: 33 additions & 33 deletions src/rust/model_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,23 +338,23 @@ pub fn multipart_field_module() -> Result<Module> {
let code = unit()
+ line(unit() + "pub trait MultipartField {")
+ indented(
unit()
+ line("fn to_multipart_field(&self) -> String;")
+ line("fn mime_type(&self) -> &'static str;"),
)
unit()
+ line("fn to_multipart_field(&self) -> String;")
+ line("fn mime_type(&self) -> &'static str;"),
)
+ line(unit() + "}")
+ NewLine
+ line(unit() + "impl<T: std::fmt::Display> MultipartField for T {")
+ indented(
unit()
+ line("fn to_multipart_field(&self) -> String {")
+ indented(line("self.to_string()"))
+ line("}")
+ NewLine
+ line(unit() + "fn mime_type(&self) -> &'static str {")
+ indented(line(r#""text/plain; charset=utf-8""#))
+ line(unit() + "}"),
)
unit()
+ line("fn to_multipart_field(&self) -> String {")
+ indented(line("self.to_string()"))
+ line("}")
+ NewLine
+ line(unit() + "fn mime_type(&self) -> &'static str {")
+ indented(line(r#""text/plain; charset=utf-8""#))
+ line(unit() + "}"),
)
+ line("}");

Ok(Module {
Expand Down Expand Up @@ -521,30 +521,30 @@ pub fn model_gen(
+ derive_line()
+ line(unit() + "pub struct " + &name + " {")
+ indented(
fields
.into_iter()
.reduce(|acc, e| acc + e)
.unwrap_or_else(unit),
)
fields
.into_iter()
.reduce(|acc, e| acc + e)
.unwrap_or_else(unit),
)
+ line(unit() + "}")
+ NewLine
+ line(
unit()
+ "impl "
+ rust_name("crate::model", "MultipartField")
+ " for "
+ &name
+ "{",
)
unit()
+ "impl "
+ rust_name("crate::model", "MultipartField")
+ " for "
+ &name
+ "{",
)
+ indented(
line(unit() + "fn to_multipart_field(&self) -> String {")
+ indented(line("serde_json::to_string(self).unwrap()"))
+ line("}")
+ NewLine
+ line(unit() + "fn mime_type(&self) -> &'static str {")
+ indented(line(r#""application/json""#))
+ line("}"),
)
line(unit() + "fn to_multipart_field(&self) -> String {")
+ indented(line("serde_json::to_string(self).unwrap()"))
+ line("}")
+ NewLine
+ line(unit() + "fn mime_type(&self) -> &'static str {")
+ indented(line(r#""application/json""#))
+ line("}"),
)
+ line("}");

Ok(code)
Expand Down
2 changes: 1 addition & 1 deletion src/rust/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use crate::printer::TreePrinter;
use crate::rust::lib_gen::ModuleName;
use crate::rust::model_gen::RefCache;
use crate::rust::printer::{rust_name, unit, RustContext};
use crate::{Error, Result};
Expand All @@ -22,7 +23,6 @@ use openapiv3::{
VariantOrUnknownOrEmpty,
};
use std::fmt::Display;
use crate::rust::lib_gen::ModuleName;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ModelType {
Expand Down

0 comments on commit 08bea85

Please sign in to comment.