summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-10-13 14:27:01 +0800
committer魏曹先生 <1992414357@qq.com>2025-10-13 14:27:01 +0800
commit4810f56e6a49b60923eb850d5944457650c81c75 (patch)
treeef02095c73635b5ace574c26dfcb999017e34897 /crates
parentacf0804b5f9bdc2796d847919a8ae20103be600a (diff)
Fix Clippy warnings and optimize code
- Fix let_underscore_future warning by properly awaiting async functions - Make accept_import function async to match add_mapping usage - Propagate errors properly with ? operator instead of ignoring them - Replace manual Default implementation with derive attribute - Replace vec! with array literal to avoid useless_vec warning - All tests pass and code is now Clippy clean
Diffstat (limited to 'crates')
-rw-r--r--crates/system_action/action_macros/src/lib.rs7
-rw-r--r--crates/system_action/src/action.rs14
-rw-r--r--crates/system_action/src/action_pool.rs48
-rw-r--r--crates/utils/tcp_connection/tcp_connection_test/src/test_msgpack.rs11
-rw-r--r--crates/vcs_actions/src/connection/action_service.rs4
-rw-r--r--crates/vcs_actions/src/registry/client_registry.rs4
-rw-r--r--crates/vcs_data/src/data/sheet.rs8
-rw-r--r--crates/vcs_data/vcs_data_test/src/test_sheet_creation_management_and_persistence.rs2
8 files changed, 51 insertions, 47 deletions
diff --git a/crates/system_action/action_macros/src/lib.rs b/crates/system_action/action_macros/src/lib.rs
index d1a47ee..ce50073 100644
--- a/crates/system_action/action_macros/src/lib.rs
+++ b/crates/system_action/action_macros/src/lib.rs
@@ -101,7 +101,7 @@ fn generate_action_struct(input_fn: ItemFn, _is_local: bool) -> proc_macro2::Tok
}
fn validate_function_signature(fn_sig: &syn::Signature) {
- if !fn_sig.asyncness.is_some() {
+ if fn_sig.asyncness.is_none() {
panic!("Expected async function for Action, but found synchronous function");
}
@@ -120,13 +120,12 @@ fn validate_function_signature(fn_sig: &syn::Signature) {
};
if let syn::Type::Path(type_path) = return_type.as_ref() {
- if let Some(segment) = type_path.path.segments.last() {
- if segment.ident != "Result" {
+ if let Some(segment) = type_path.path.segments.last()
+ && segment.ident != "Result" {
panic!(
"Expected Action function to return Result<T, TcpTargetError>, but found different return type"
);
}
- }
} else {
panic!(
"Expected Action function to return Result<T, TcpTargetError>, but found no return type"
diff --git a/crates/system_action/src/action.rs b/crates/system_action/src/action.rs
index 3ae5711..8a6180a 100644
--- a/crates/system_action/src/action.rs
+++ b/crates/system_action/src/action.rs
@@ -41,16 +41,18 @@ pub struct ActionContext {
impl ActionContext {
/// Generate local context
pub fn local() -> Self {
- let mut ctx = ActionContext::default();
- ctx.local = true;
- ctx
+ ActionContext {
+ local: true,
+ ..Default::default()
+ }
}
/// Generate remote context
pub fn remote() -> Self {
- let mut ctx = ActionContext::default();
- ctx.local = false;
- ctx
+ ActionContext {
+ local: false,
+ ..Default::default()
+ }
}
/// Build connection instance from TcpStream
diff --git a/crates/system_action/src/action_pool.rs b/crates/system_action/src/action_pool.rs
index f3e178a..c28de1e 100644
--- a/crates/system_action/src/action_pool.rs
+++ b/crates/system_action/src/action_pool.rs
@@ -6,12 +6,14 @@ use tcp_connection::error::TcpTargetError;
use crate::action::{Action, ActionContext};
-type ProcBeginCallback =
- for<'a> fn(
- &'a ActionContext,
- args: &'a (dyn std::any::Any + Send + Sync),
- ) -> Pin<Box<dyn Future<Output = Result<(), TcpTargetError>> + Send + 'a>>;
-type ProcEndCallback = fn() -> Pin<Box<dyn Future<Output = Result<(), TcpTargetError>> + Send>>;
+type ProcBeginCallback = for<'a> fn(
+ &'a ActionContext,
+ args: &'a (dyn std::any::Any + Send + Sync),
+) -> ProcBeginFuture<'a>;
+type ProcEndCallback = fn() -> ProcEndFuture;
+
+type ProcBeginFuture<'a> = Pin<Box<dyn Future<Output = Result<(), TcpTargetError>> + Send + 'a>>;
+type ProcEndFuture = Pin<Box<dyn Future<Output = Result<(), TcpTargetError>> + Send>>;
/// A pool of registered actions that can be processed by name
pub struct ActionPool {
@@ -25,6 +27,12 @@ pub struct ActionPool {
on_proc_end: Option<ProcEndCallback>,
}
+impl Default for ActionPool {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl ActionPool {
/// Creates a new empty ActionPool
pub fn new() -> Self {
@@ -88,9 +96,9 @@ impl ActionPool {
let context = context.set_action_name(action_name.to_string());
let context = context.set_action_args(args_json.clone());
- let _ = self.exec_on_proc_begin(&context, &args_json).await?;
+ self.exec_on_proc_begin(&context, &args_json).await?;
let result = action.process_json_erased(context, args_json).await?;
- let _ = self.exec_on_proc_end().await?;
+ self.exec_on_proc_end().await?;
Ok(result)
} else {
Err(TcpTargetError::Unsupported("InvalidAction".to_string()))
@@ -106,7 +114,7 @@ impl ActionPool {
pub async fn process<'a, Args, Return>(
&'a self,
action_name: &'a str,
- mut context: ActionContext,
+ context: ActionContext,
args: Args,
) -> Result<Return, TcpTargetError>
where
@@ -114,12 +122,12 @@ impl ActionPool {
Return: serde::Serialize + Send + 'static,
{
if let Some(action) = self.actions.get(action_name) {
- let _ = self.exec_on_proc_begin(&context, &args).await?;
+ self.exec_on_proc_begin(&context, &args).await?;
let result = action.process_erased(context, Box::new(args)).await?;
let result = *result
.downcast::<Return>()
.map_err(|_| TcpTargetError::Unsupported("InvalidArguments".to_string()))?;
- let _ = self.exec_on_proc_end().await?;
+ self.exec_on_proc_end().await?;
Ok(result)
} else {
Err(TcpTargetError::Unsupported("InvalidAction".to_string()))
@@ -150,25 +158,29 @@ impl ActionPool {
}
/// Trait for type-erased actions that can be stored in ActionPool
+type ProcessErasedFuture = std::pin::Pin<
+ Box<
+ dyn std::future::Future<Output = Result<Box<dyn std::any::Any + Send>, TcpTargetError>>
+ + Send,
+ >,
+>;
+type ProcessJsonErasedFuture =
+ std::pin::Pin<Box<dyn std::future::Future<Output = Result<String, TcpTargetError>> + Send>>;
+
trait ActionErased: Send + Sync {
/// Processes the action with type-erased arguments and returns type-erased result
fn process_erased(
&self,
context: ActionContext,
args: Box<dyn std::any::Any + Send>,
- ) -> std::pin::Pin<
- Box<
- dyn std::future::Future<Output = Result<Box<dyn std::any::Any + Send>, TcpTargetError>>
- + Send,
- >,
- >;
+ ) -> ProcessErasedFuture;
/// Processes the action with JSON-serialized arguments and returns JSON-serialized result
fn process_json_erased(
&self,
context: ActionContext,
args_json: String,
- ) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<String, TcpTargetError>> + Send>>;
+ ) -> ProcessJsonErasedFuture;
}
/// Wrapper struct that implements ActionErased for concrete Action types
diff --git a/crates/utils/tcp_connection/tcp_connection_test/src/test_msgpack.rs b/crates/utils/tcp_connection/tcp_connection_test/src/test_msgpack.rs
index 7a7dc1f..4c9c870 100644
--- a/crates/utils/tcp_connection/tcp_connection_test/src/test_msgpack.rs
+++ b/crates/utils/tcp_connection/tcp_connection_test/src/test_msgpack.rs
@@ -9,21 +9,12 @@ use crate::test_utils::{
target_configure::ServerTargetConfig,
};
-#[derive(Debug, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, PartialEq, Serialize, Deserialize, Default)]
struct TestData {
id: u32,
name: String,
}
-impl Default for TestData {
- fn default() -> Self {
- Self {
- id: 0,
- name: String::new(),
- }
- }
-}
-
pub(crate) struct MsgPackClientHandle;
impl ClientHandle<MsgPackServerHandle> for MsgPackClientHandle {
diff --git a/crates/vcs_actions/src/connection/action_service.rs b/crates/vcs_actions/src/connection/action_service.rs
index 0a49953..c302fd4 100644
--- a/crates/vcs_actions/src/connection/action_service.rs
+++ b/crates/vcs_actions/src/connection/action_service.rs
@@ -30,7 +30,7 @@ pub async fn server_entry(vault_path: impl Into<PathBuf>) -> Result<(), TcpTarge
// Start the server
let (_shutdown_rx, future) = build_server_future(vault.clone(), action_pool.clone(), listener);
- let _ = future.await?; // Start and block until shutdown
+ future.await?; // Start and block until shutdown
Ok(())
}
@@ -38,7 +38,7 @@ pub async fn server_entry(vault_path: impl Into<PathBuf>) -> Result<(), TcpTarge
async fn create_tcp_listener(cfg: &VaultConfig) -> Result<TcpListener, TcpTargetError> {
let local_bind_addr = cfg.server_config().local_bind();
let bind_port = cfg.server_config().port();
- let sock_addr = SocketAddr::new(local_bind_addr.clone(), bind_port);
+ let sock_addr = SocketAddr::new(*local_bind_addr, bind_port);
let listener = TcpListener::bind(sock_addr).await?;
Ok(listener)
diff --git a/crates/vcs_actions/src/registry/client_registry.rs b/crates/vcs_actions/src/registry/client_registry.rs
index 47fd7ee..5939bed 100644
--- a/crates/vcs_actions/src/registry/client_registry.rs
+++ b/crates/vcs_actions/src/registry/client_registry.rs
@@ -46,8 +46,8 @@ async fn on_proc_begin(
if is_remote {
// Build protocol message
let msg = RemoteActionInvoke {
- action_name: action_name,
- action_args_json: action_args_json,
+ action_name,
+ action_args_json,
};
// Send
diff --git a/crates/vcs_data/src/data/sheet.rs b/crates/vcs_data/src/data/sheet.rs
index a6220c9..f1cf67c 100644
--- a/crates/vcs_data/src/data/sheet.rs
+++ b/crates/vcs_data/src/data/sheet.rs
@@ -107,7 +107,7 @@ impl<'a> Sheet<'a> {
}
/// Accept an input package and insert to the sheet
- pub fn accept_import(
+ pub async fn accept_import(
&mut self,
input_name: &InputName,
insert_to: &SheetPathBuf,
@@ -129,7 +129,8 @@ impl<'a> Sheet<'a> {
// Insert to sheet
for (relative_path, virtual_file_id) in input.files {
- let _ = self.add_mapping(insert_to.join(relative_path), virtual_file_id);
+ self.add_mapping(insert_to.join(relative_path), virtual_file_id)
+ .await?;
}
Ok(())
@@ -176,8 +177,7 @@ impl<'a> Sheet<'a> {
}
Err(_) => {
// Error checking rights, don't allow modifying the mapping
- Err(std::io::Error::new(
- std::io::ErrorKind::Other,
+ Err(std::io::Error::other(
"Failed to check virtual file edit rights",
))
}
diff --git a/crates/vcs_data/vcs_data_test/src/test_sheet_creation_management_and_persistence.rs b/crates/vcs_data/vcs_data_test/src/test_sheet_creation_management_and_persistence.rs
index 461d465..a8dfb89 100644
--- a/crates/vcs_data/vcs_data_test/src/test_sheet_creation_management_and_persistence.rs
+++ b/crates/vcs_data/vcs_data_test/src/test_sheet_creation_management_and_persistence.rs
@@ -254,7 +254,7 @@ async fn test_sheet_data_serialization() -> Result<(), std::io::Error> {
// Add some inputs
let input_name = "source_files".to_string();
- let _files = vec![
+ let _files = [
(
InputRelativePathBuf::from("src/main.rs"),
VirtualFileId::new(),