Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit ab09bbf

Browse files
committed
Clippy
1 parent 3a18704 commit ab09bbf

1 file changed

Lines changed: 18 additions & 21 deletions

File tree

golem-rust-macro/src/wit_gen.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,19 @@ pub fn generate_witfile(ast: &mut syn::ItemMod, file_name: String) -> syn::Resul
5252
.to_lowercase()
5353
.replace('_', "-");
5454

55-
resolve_type(f.ty).map(|tpe| format!("{}: {}", field_name, tpe))
55+
resolve_type(f.ty).map(|tpe| format!("{field_name}: {tpe}"))
5656
})
5757
.collect();
5858
let joined = fields?.join(", \n\t\t");
5959

6060
if joined.is_empty() {
61-
Ok(format!(" record {} {{}}", record_title))
61+
Ok(format!(" record {record_title} {{}}"))
6262
} else {
6363
Ok(format!(
6464
"
65-
record {} {{
66-
{},
67-
}}",
68-
record_title, joined
65+
record {record_title} {{
66+
{joined},
67+
}}"
6968
))
7069
}
7170
}
@@ -112,14 +111,12 @@ pub fn generate_witfile(ast: &mut syn::ItemMod, file_name: String) -> syn::Resul
112111
if ret_tpe.is_empty() {
113112
format!(
114113
"
115-
{}: func({})",
116-
fun_title, params
114+
{fun_title}: func({params})"
117115
)
118116
} else {
119117
format!(
120118
"
121-
{}: func({}) -> {}",
122-
fun_title, params, ret_tpe
119+
{fun_title}: func({params}) -> {ret_tpe}"
123120
)
124121
}
125122
})
@@ -168,17 +165,17 @@ pub fn generate_witfile(ast: &mut syn::ItemMod, file_name: String) -> syn::Resul
168165

169166
Ok(format!(
170167
"
171-
{} {} {{
172-
{}
168+
{keyword} {variant_title} {{
169+
{var_body}
173170
}}
174-
", keyword, variant_title, var_body
171+
"
175172
))
176173
},
177174
Item::Type(type_item) => {
178175
let ident = pascal_case_to_kebab_case(type_item.ident.to_string());
179176
let tpe = resolve_type(*type_item.ty)?;
180177

181-
Ok(format!(" type {} = {}", ident, tpe))
178+
Ok(format!(" type {ident} = {tpe}"))
182179
},
183180
a => Err(syn::Error::new(
184181
a.span(),
@@ -331,7 +328,7 @@ fn resolve_type(ty: Type) -> syn::Result<String> {
331328
GenericArgument::Type(tpe) => {
332329
let tpe_name = resolve_type(tpe.clone());
333330

334-
tpe_name.map(|t| format!("list<{}>", t))
331+
tpe_name.map(|t| format!("list<{t}>"))
335332
}
336333
_ => Err(syn::Error::new(ty.span(), "Unexpected error. If you think this should work, please open an issue and describe your use case. https://github.com/golemcloud/golem-rust/issues")),
337334
}
@@ -357,7 +354,7 @@ fn resolve_type(ty: Type) -> syn::Result<String> {
357354
GenericArgument::Type(tpe) => {
358355
let tpe_name = resolve_type(tpe.clone());
359356

360-
tpe_name.map(|t| format!("option<{}>", t))
357+
tpe_name.map(|t| format!("option<{t}>"))
361358
}
362359
_ => Err(syn::Error::new(ty.span(), "Unexpected error. If you think this should work, please open an issue and describe your use case. https://github.com/golemcloud/golem-rust/issues")),
363360
}
@@ -375,11 +372,11 @@ fn resolve_type(ty: Type) -> syn::Result<String> {
375372
if t.is_empty() {
376373
"".to_string()
377374
} else {
378-
format!("tuple<{}>", t)
375+
format!("tuple<{t}>")
379376
}
380377
})
381378
}
382-
Type::Slice(type_slice) => resolve_type(*type_slice.elem).map(|t| format!("list<{}>", t)),
379+
Type::Slice(type_slice) => resolve_type(*type_slice.elem).map(|t| format!("list<{t}>")),
383380
_ => Ok("".to_owned()),
384381
}
385382
}
@@ -411,7 +408,7 @@ world golem-service {{
411408
let mut old_content = String::new();
412409

413410
file.read_to_string(&mut old_content)
414-
.map_err(|e| syn::Error::new(ast_span, format!("Error while reading from file {}", e)))?;
411+
.map_err(|e| syn::Error::new(ast_span, format!("Error while reading from file {e}")))?;
415412

416413
if old_content == new_content {
417414
// do nothing
@@ -429,10 +426,10 @@ world golem-service {{
429426

430427
fn create_and_write_to_file(file_name: String, new_content: String, ast_span: Span) -> Result<()> {
431428
let mut file = File::create(file_name.clone())
432-
.map_err(|e| syn::Error::new(ast_span, format!("Error while creating file {}", e)))?;
429+
.map_err(|e| syn::Error::new(ast_span, format!("Error while creating file {e}")))?;
433430

434431
file.write_all(new_content.trim().as_bytes())
435-
.map_err(|e| syn::Error::new(ast_span, format!("Error while writing to file {}", e)))?;
432+
.map_err(|e| syn::Error::new(ast_span, format!("Error while writing to file {e}")))?;
436433

437434
Ok(())
438435
}

0 commit comments

Comments
 (0)