From 14c6e3a03109e1192f33adb36a1939c541ada168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Vasconcellos?= Date: Fri, 9 Aug 2024 21:09:04 -0300 Subject: [PATCH] Update tauri - Remove broken example from compiling - Filter out some broken tests - Clippy auto format --- Cargo.toml | 4 ++-- httpz/Cargo.toml | 2 -- src/alpha/layer.rs | 16 ++++++++-------- src/alpha/mod.rs | 5 +++-- src/alpha/procedure.rs | 12 ++++++------ src/alpha/router.rs | 9 +++++++++ src/alpha/rspc.rs | 4 ++-- src/alpha/unstable/mw_arg_mapper.rs | 6 ++++++ src/alpha_stable/mod.rs | 6 ++++++ src/integrations/httpz.rs | 3 +-- src/integrations/tauri.rs | 13 +++++-------- src/internal/jsonrpc_exec.rs | 8 +++----- src/internal/mod.rs | 1 + 13 files changed, 52 insertions(+), 37 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a6849393..050aab37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,7 @@ serde_json = "1.0.95" thiserror = "1.0.40" futures = "0.3.28" tokio = { version = "1.27.0", features = ["sync", "rt", "macros"] } -tauri = { version = "=2.0.0-beta.17", optional = true } +tauri = { version = "=2.0.0-rc.2", optional = true } tracing = { version = "0.1.37", optional = true } anyhow = { version = "1", optional = true } futures-locks = { version = "0.7.1", features = ["tokio"] } @@ -71,4 +71,4 @@ pprof = { version = "0.11.1", features = ["flamegraph", "criterion", "protobuf-c tokio = { version = "1.27.0", features = ["macros", "rt-multi-thread"] } [workspace] -members = ["./httpz", "./examples", "./examples/axum"] +members = ["./httpz"] diff --git a/httpz/Cargo.toml b/httpz/Cargo.toml index efdc124f..ab992794 100644 --- a/httpz/Cargo.toml +++ b/httpz/Cargo.toml @@ -39,7 +39,6 @@ poem = ["dep:poem"] rocket = ["dep:rocket"] warp = ["dep:warp"] lambda = ["dep:lambda_http", "dep:tower"] -# tauri = ["dep:tauri", "dep:percent-encoding", "dep:tokio"] # TODO: Remove tokio dep once my wry & Tauri PR's are merged [dependencies] # Webservers @@ -50,7 +49,6 @@ rocket = { version = "0.5.0-rc.3", optional = true, features = [] } warp = { version = "0.3.5", optional = true, features = [] } lambda_http = { version = "0.8.1", optional = true, features = [] } tower = { version = "0.4.13", optional = true, features = [] } -# tauri = { version = "1.4.1", optional = true, features = ["linux-protocol-headers"] } # Core cookie = { version = "0.17.0", optional = true, features = ["percent-encode"] } diff --git a/src/alpha/layer.rs b/src/alpha/layer.rs index 57385b51..65077e7c 100644 --- a/src/alpha/layer.rs +++ b/src/alpha/layer.rs @@ -8,12 +8,12 @@ use crate::{internal::RequestContext, ExecError}; pub trait AlphaLayer: DynLayer + Send + Sync + 'static { type Stream<'a>: Stream> + Send + 'a; - fn call<'a>( - &'a self, + fn call( + &self, a: TLayerCtx, b: Value, c: RequestContext, - ) -> Result, ExecError>; + ) -> Result, ExecError>; fn erase(self) -> Box> where @@ -28,17 +28,17 @@ pub type FutureValueOrStream<'a> = Pin> + Send + 'a>>; pub trait DynLayer: Send + Sync + 'static { - fn dyn_call<'a>(&'a self, a: TLayerCtx, b: Value, c: RequestContext) - -> FutureValueOrStream<'a>; + fn dyn_call(&self, a: TLayerCtx, b: Value, c: RequestContext) + -> FutureValueOrStream<'_>; } impl> DynLayer for L { - fn dyn_call<'a>( - &'a self, + fn dyn_call( + &self, a: TLayerCtx, b: Value, c: RequestContext, - ) -> FutureValueOrStream<'a> { + ) -> FutureValueOrStream<'_> { match self.call(a, b, c) { Ok(stream) => Box::pin(stream), Err(err) => Box::pin(once(ready(Err(err)))), diff --git a/src/alpha/mod.rs b/src/alpha/mod.rs index 342b49bb..c10b39e2 100644 --- a/src/alpha/mod.rs +++ b/src/alpha/mod.rs @@ -25,6 +25,7 @@ pub use crate::alpha_stable::*; pub mod unstable; #[cfg(test)] +#[cfg(feature = "unstable")] mod tests { use std::{path::PathBuf, time::Duration}; @@ -178,7 +179,7 @@ mod tests { )) .query(|ctx, _: ()| { println!("TODO: {:?}", ctx); - let _ = ctx.0; // Test Rust inference is working + ctx.0; // Test Rust inference is working Ok(()) }); } @@ -231,7 +232,7 @@ mod tests { )) .query(|_, _: i32| Ok(())); - let _r = R + R .router() .procedure("demo", p) .compat() diff --git a/src/alpha/procedure.rs b/src/alpha/procedure.rs index 1f5c552f..8bd54612 100644 --- a/src/alpha/procedure.rs +++ b/src/alpha/procedure.rs @@ -336,12 +336,12 @@ where { type Stream<'a> = MiddlewareFutOrSomething<'a, TLayerCtx, TNewMiddleware, TMiddleware>; - fn call<'a>( - &'a self, + fn call( + &self, ctx: TLayerCtx, input: Value, req: RequestContext, - ) -> Result, ExecError> { + ) -> Result, ExecError> { let fut = self.mw.run_me( ctx, super::middleware::AlphaMiddlewareContext { @@ -513,12 +513,12 @@ where { type Stream<'a> = S; - fn call<'a>( - &'a self, + fn call( + &self, a: TLayerCtx, b: Value, c: RequestContext, - ) -> Result, ExecError> { + ) -> Result, ExecError> { (self.func)(a, b, c) } } diff --git a/src/alpha/router.rs b/src/alpha/router.rs index d5c6fa68..81eccf8b 100644 --- a/src/alpha/router.rs +++ b/src/alpha/router.rs @@ -21,6 +21,15 @@ where dangerously_map_types: Option>, } +impl Default for AlphaRouter +where + TCtx: Send + Sync + 'static, + { + fn default() -> Self { + Self::new() + } +} + impl AlphaRouter where TCtx: Send + Sync + 'static, diff --git a/src/alpha/rspc.rs b/src/alpha/rspc.rs index 0a6d6c58..39d7b577 100644 --- a/src/alpha/rspc.rs +++ b/src/alpha/rspc.rs @@ -1,9 +1,9 @@ use std::marker::PhantomData; use super::{ - middleware::AlphaMiddlewareContext, procedure::AlphaProcedure, AlphaBaseMiddleware, + procedure::AlphaProcedure, AlphaBaseMiddleware, AlphaMiddlewareLayerBuilder, AlphaRequestLayer, AlphaRouter, FutureMarker, MissingResolver, - MwV2, MwV2Result, RequestKind, RequestLayerMarker, ResolverFunction, StreamLayerMarker, + MwV2, RequestKind, RequestLayerMarker, ResolverFunction, StreamLayerMarker, StreamMarker, }; diff --git a/src/alpha/unstable/mw_arg_mapper.rs b/src/alpha/unstable/mw_arg_mapper.rs index 110ad3bc..40b3cf05 100644 --- a/src/alpha/unstable/mw_arg_mapper.rs +++ b/src/alpha/unstable/mw_arg_mapper.rs @@ -25,6 +25,12 @@ pub trait MwArgMapper: Send + Sync { pub struct MwArgMapperMiddleware(PhantomData); +impl Default for MwArgMapperMiddleware { + fn default() -> Self { + Self::new() + } +} + impl MwArgMapperMiddleware { pub const fn new() -> Self { Self(PhantomData) diff --git a/src/alpha_stable/mod.rs b/src/alpha_stable/mod.rs index 417cc4ab..53379bc4 100644 --- a/src/alpha_stable/mod.rs +++ b/src/alpha_stable/mod.rs @@ -39,6 +39,12 @@ impl RequestLayerMarker { #[doc(hidden)] pub struct StreamLayerMarker(PhantomData); +impl Default for StreamLayerMarker { + fn default() -> Self { + Self::new() + } +} + impl StreamLayerMarker { pub fn new() -> Self { Self(Default::default()) diff --git a/src/integrations/httpz.rs b/src/integrations/httpz.rs index 453cf710..cbdba155 100644 --- a/src/integrations/httpz.rs +++ b/src/integrations/httpz.rs @@ -10,7 +10,6 @@ use serde_json::Value; use std::{ borrow::Cow, collections::HashMap, - mem, sync::{Arc, Mutex}, }; @@ -202,7 +201,7 @@ impl Request { pub fn cookies(&mut self) -> Option { // TODO: This take means a `None` response could be because it was already used or because it's a websocket. This is a confusing DX and needs fixing. - mem::replace(&mut self.1, None) + self.1.take() } /// query_pairs returns an iterator of the query parameters. diff --git a/src/integrations/tauri.rs b/src/integrations/tauri.rs index c864a191..3e298e01 100644 --- a/src/integrations/tauri.rs +++ b/src/integrations/tauri.rs @@ -3,7 +3,6 @@ use std::{ collections::{hash_map::DefaultHasher, HashMap}, future::{ready, Ready}, hash::{Hash, Hasher}, - marker::PhantomData, sync::{Arc, Mutex}, }; @@ -12,7 +11,7 @@ use serde_json::Value; use tauri::{ async_runtime::spawn, plugin::{Builder, TauriPlugin}, - Manager, Window, WindowEvent, Wry, + Emitter, Listener, Window, WindowEvent, Wry, }; use tokio::sync::oneshot; @@ -197,11 +196,10 @@ where webview.window().on_window_event({ let webview = webview.clone(); let manager = manager.clone(); - move |event| match event { - WindowEvent::CloseRequested { .. } => { + move |event| { + if let WindowEvent::CloseRequested { .. } = event { manager.close_requested(&webview.window()); } - _ => {} } }) }) @@ -224,11 +222,10 @@ where webview.window().on_window_event({ let webview = webview.clone(); let manager = manager.clone(); - move |event| match event { - WindowEvent::CloseRequested { .. } => { + move |event| { + if let WindowEvent::CloseRequested { .. } = event { manager.close_requested(&webview.window()); } - _ => {} } }) }) diff --git a/src/internal/jsonrpc_exec.rs b/src/internal/jsonrpc_exec.rs index aa31041e..fbb0c2e9 100644 --- a/src/internal/jsonrpc_exec.rs +++ b/src/internal/jsonrpc_exec.rs @@ -229,7 +229,6 @@ where result: ResponseInner::Error(err.into()), }) .await; - return; } } } @@ -315,7 +314,6 @@ where result: ResponseInner::Error(err.into()), }) .await; - return; } } } @@ -409,7 +407,7 @@ where sender .send(jsonrpc::Response { jsonrpc: "2.0", - id: id, + id, result: ResponseInner::Error(err.into()), }) .await; @@ -479,12 +477,12 @@ where .await; } }, - }; + } } } // TODO: Can this we removed? -fn to_owned<'a, T>(arc: Cow<'a, Arc>) -> Arc { +fn to_owned(arc: Cow<'_, Arc>) -> Arc { match arc { Cow::Borrowed(arc) => arc.to_owned(), Cow::Owned(arc) => arc, diff --git a/src/internal/mod.rs b/src/internal/mod.rs index 6c93a2a0..1cb21d23 100644 --- a/src/internal/mod.rs +++ b/src/internal/mod.rs @@ -19,6 +19,7 @@ pub use procedure_store::*; pub use specta; #[cfg(test)] +#[cfg(not(feature = "unstable"))] mod tests { use std::{fs::File, io::Write, path::PathBuf};