From f7ec6855da1985e8efd7b77b606ad858e729b851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E6=AC=A7?= Date: Thu, 21 Dec 2023 13:20:08 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Fix=20clippy.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/host-side/src/main.rs | 2 +- packages/macro-types/Cargo.toml | 17 +++++++++++++++++ packages/macro-types/src/lib.rs | 1 + packages/macro/Cargo.toml | 14 ++++++++++++++ .../src/routes/backend/functions/users.rs | 16 ++++++++-------- .../router/src/routes/backend/secure/login.rs | 10 +++++----- .../src/routes/backend/secure/register.rs | 10 +++++----- .../router/src/routes/backend/secure/verify.rs | 4 ++-- packages/router/src/routes/mod.rs | 2 +- packages/router/src/routes/utils.rs | 2 +- packages/vm/src/runtime.rs | 2 +- packages/vm/src/stream.rs | 4 +++- 12 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 packages/macro-types/Cargo.toml create mode 100644 packages/macro-types/src/lib.rs diff --git a/examples/host-side/src/main.rs b/examples/host-side/src/main.rs index 52629d9..a21b4a7 100644 --- a/examples/host-side/src/main.rs +++ b/examples/host-side/src/main.rs @@ -116,7 +116,7 @@ async fn main() -> Result<()> { }, ); } - ret.push(map.into()); + ret.push(map); } } _ => unreachable!("Unsupported payload: {:?}", payload), diff --git a/packages/macro-types/Cargo.toml b/packages/macro-types/Cargo.toml new file mode 100644 index 0000000..45ea12c --- /dev/null +++ b/packages/macro-types/Cargo.toml @@ -0,0 +1,17 @@ +[package] +authors = ["langyo "] +name = "tairitsu-macro-types" + +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +anyhow = "^1" +async-trait = "^0.1" +base64 = "^0.21" +derive_more = "*" +serde = { version = "^1", features = ["derive"] } +serde_json = "^1" +strum = "^0.25" +strum_macros = "^0.25" diff --git a/packages/macro-types/src/lib.rs b/packages/macro-types/src/lib.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/packages/macro-types/src/lib.rs @@ -0,0 +1 @@ + diff --git a/packages/macro/Cargo.toml b/packages/macro/Cargo.toml index a73bf1c..bb03490 100644 --- a/packages/macro/Cargo.toml +++ b/packages/macro/Cargo.toml @@ -8,3 +8,17 @@ publish = false [lib] proc-macro = true + +[dependencies] +tairitsu-macro-types = { path = "../macro-types" } + +anyhow = "^1" +derive_more = "*" +serde = { version = "^1", features = ["derive"] } +serde_json = "^1" +strum = "^0.25" +strum_macros = "^0.25" + +syn = { version = "^2", features = ["full"] } +proc-macro2 = "^1" +quote = "^1" diff --git a/packages/router/src/routes/backend/functions/users.rs b/packages/router/src/routes/backend/functions/users.rs index 6e4bd6a..55d787f 100644 --- a/packages/router/src/routes/backend/functions/users.rs +++ b/packages/router/src/routes/backend/functions/users.rs @@ -18,20 +18,20 @@ async fn query(Json(item): Json) -> Result Result { let ret = functions::count() .await - .or_else(|e| Err(generate_error_message(e.to_string())))?; + .map_err(|e| generate_error_message(e.to_string()))?; let ret = Count { count: ret }; let ret = ResponsePackage::Data(vec![ResponseStruct::Count(ret)]); - to_string(&ret).or_else(|e| Err(generate_error_message(e.to_string()))) + to_string(&ret).map_err(|e| generate_error_message(e.to_string())) } async fn list(Json(item): Json) -> Result { @@ -42,14 +42,14 @@ async fn list(Json(item): Json) -> Result) -> Result { @@ -60,7 +60,7 @@ async fn update(Json(item): Json) -> Result) -> Result) -> Result) -> Result) -> Result Result { let ret = ResponsePackage::Data(vec![ResponseStruct::Ok]); - to_string(&ret).or_else(|e| Err(generate_error_message(e.to_string()))) + to_string(&ret).map_err(|e| generate_error_message(e.to_string())) } pub fn generate_error_message(message: String) -> (StatusCode, String) { diff --git a/packages/vm/src/runtime.rs b/packages/vm/src/runtime.rs index 682e421..86834a6 100644 --- a/packages/vm/src/runtime.rs +++ b/packages/vm/src/runtime.rs @@ -91,7 +91,7 @@ impl Image { .precompile_component(component.as_ref()) .expect("Cannot compile module"), ); - let component = unsafe { Component::deserialize(&engine, &cwasm.as_ref()).unwrap() }; + let component = unsafe { Component::deserialize(&engine, cwasm.as_ref()).unwrap() }; Self { engine, component } } diff --git a/packages/vm/src/stream.rs b/packages/vm/src/stream.rs index e829c72..8063742 100644 --- a/packages/vm/src/stream.rs +++ b/packages/vm/src/stream.rs @@ -63,7 +63,9 @@ impl HostOutputStream for OutputStream { self.buffer.clear(); Ok(()) } else { - Err(StreamError::LastOperationFailed(anyhow::anyhow!("Failed to parse message")).into()) + Err(StreamError::LastOperationFailed(anyhow::anyhow!( + "Failed to parse message" + ))) } }