diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-20 21:54:29 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-20 21:57:49 +0800 |
| commit | 9a60751a901f568bdeb154c4115235d4f3a0f8b9 (patch) | |
| tree | 65df323f6478bae51473a3d6471df39a596ce9c5 /systems/_constants/macros | |
| parent | a9e5c086584d3e697188be7003f564e7e2137135 (diff) | |
Apply clippy suggestions and improve code quality
Diffstat (limited to 'systems/_constants/macros')
| -rw-r--r-- | systems/_constants/macros/src/lib.rs | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/systems/_constants/macros/src/lib.rs b/systems/_constants/macros/src/lib.rs index 7384182..90419c1 100644 --- a/systems/_constants/macros/src/lib.rs +++ b/systems/_constants/macros/src/lib.rs @@ -28,7 +28,7 @@ pub fn constants(attr: TokenStream, item: TokenStream) -> TokenStream { { // Process constant and generate functions if let Some((rust_func, ffi_func)) = - process_constant(&prefix, const_name, const_value) + process_constant(&prefix, const_name, &const_value) { generated_functions.push(rust_func); generated_ffi_functions.push(ffi_func); @@ -51,12 +51,12 @@ pub fn constants(attr: TokenStream, item: TokenStream) -> TokenStream { } fn extract_const_name_and_value(assign: &syn::ExprAssign) -> Option<(Ident, Box<Expr>)> { - if let Expr::Path(path) = &*assign.left { - if let Some(ident) = path.path.get_ident() { - let const_name = ident.clone(); - let const_value = assign.right.clone(); - return Some((const_name, const_value)); - } + if let Expr::Path(path) = &*assign.left + && let Some(ident) = path.path.get_ident() + { + let const_name = ident.clone(); + let const_value = assign.right.clone(); + return Some((const_name, const_value)); } None } @@ -64,12 +64,12 @@ fn extract_const_name_and_value(assign: &syn::ExprAssign) -> Option<(Ident, Box< fn process_constant( prefix: &str, const_name: Ident, - const_value: Box<Expr>, + const_value: &Expr, ) -> Option<(proc_macro2::TokenStream, proc_macro2::TokenStream)> { if let Expr::Lit(ExprLit { lit: Lit::Str(lit_str), .. - }) = *const_value + }) = const_value { let value_str = lit_str.value(); let value_span = lit_str.span(); @@ -209,18 +209,16 @@ fn generate_functions_with_params( let ffi_func = quote! { #[unsafe(no_mangle)] #[allow(nonstandard_style)] - pub extern "C" fn #ffi_fn_ident(#(#ffi_param_decls),*) -> *mut libc::c_char { - unsafe { - #(#ffi_param_checks)* + pub unsafe extern "C" fn #ffi_fn_ident(#(#ffi_param_decls),*) -> *mut libc::c_char { + #(#ffi_param_checks)* - #(#ffi_param_conversions)* + #(#ffi_param_conversions)* - let result = format!(#format_str, #(#ffi_format_args),*); + let result = format!(#format_str, #(#ffi_format_args),*); - match std::ffi::CString::new(result) { - Ok(c) => c.into_raw(), - Err(_) => std::ptr::null_mut(), - } + match std::ffi::CString::new(result) { + Ok(c) => c.into_raw(), + Err(_) => std::ptr::null_mut(), } } }; |
