Skip to content

Commit

Permalink
Update tauri
Browse files Browse the repository at this point in the history
 - Remove broken example from compiling
 - Filter out some broken tests
 - Clippy auto format
  • Loading branch information
HeavenVolkoff committed Aug 10, 2024
1 parent 14f5026 commit 14c6e3a
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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"]
2 changes: 0 additions & 2 deletions httpz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"] }
Expand Down
16 changes: 8 additions & 8 deletions src/alpha/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use crate::{internal::RequestContext, ExecError};
pub trait AlphaLayer<TLayerCtx: 'static>: DynLayer<TLayerCtx> + Send + Sync + 'static {
type Stream<'a>: Stream<Item = Result<Value, ExecError>> + Send + 'a;

fn call<'a>(
&'a self,
fn call(
&self,
a: TLayerCtx,
b: Value,
c: RequestContext,
) -> Result<Self::Stream<'a>, ExecError>;
) -> Result<Self::Stream<'_>, ExecError>;

fn erase(self) -> Box<dyn DynLayer<TLayerCtx>>
where
Expand All @@ -28,17 +28,17 @@ pub type FutureValueOrStream<'a> =
Pin<Box<dyn Stream<Item = Result<Value, ExecError>> + Send + 'a>>;

pub trait DynLayer<TLayerCtx: 'static>: 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<TLayerCtx: Send + 'static, L: AlphaLayer<TLayerCtx>> DynLayer<TLayerCtx> 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)))),
Expand Down
5 changes: 3 additions & 2 deletions src/alpha/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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(())
});
}
Expand Down Expand Up @@ -231,7 +232,7 @@ mod tests {
))
.query(|_, _: i32| Ok(()));

let _r = R
R
.router()
.procedure("demo", p)
.compat()
Expand Down
12 changes: 6 additions & 6 deletions src/alpha/procedure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Stream<'a>, ExecError> {
) -> Result<Self::Stream<'_>, ExecError> {
let fut = self.mw.run_me(
ctx,
super::middleware::AlphaMiddlewareContext {
Expand Down Expand Up @@ -513,12 +513,12 @@ where
{
type Stream<'a> = S;

fn call<'a>(
&'a self,
fn call(
&self,
a: TLayerCtx,
b: Value,
c: RequestContext,
) -> Result<Self::Stream<'a>, ExecError> {
) -> Result<Self::Stream<'_>, ExecError> {
(self.func)(a, b, c)
}
}
9 changes: 9 additions & 0 deletions src/alpha/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ where
dangerously_map_types: Option<Box<dyn FnOnce(&mut TypeMap) + Send + Sync + 'static>>,
}

impl<TCtx> Default for AlphaRouter<TCtx>
where
TCtx: Send + Sync + 'static,
{
fn default() -> Self {
Self::new()
}
}

impl<TCtx> AlphaRouter<TCtx>
where
TCtx: Send + Sync + 'static,
Expand Down
4 changes: 2 additions & 2 deletions src/alpha/rspc.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand Down
6 changes: 6 additions & 0 deletions src/alpha/unstable/mw_arg_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ pub trait MwArgMapper: Send + Sync {

pub struct MwArgMapperMiddleware<M: MwArgMapper>(PhantomData<M>);

impl<M: MwArgMapper + 'static> Default for MwArgMapperMiddleware<M> {
fn default() -> Self {
Self::new()
}
}

impl<M: MwArgMapper + 'static> MwArgMapperMiddleware<M> {
pub const fn new() -> Self {
Self(PhantomData)
Expand Down
6 changes: 6 additions & 0 deletions src/alpha_stable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ impl<T> RequestLayerMarker<T> {
#[doc(hidden)]
pub struct StreamLayerMarker<T>(PhantomData<T>);

impl<T> Default for StreamLayerMarker<T> {
fn default() -> Self {
Self::new()
}
}

impl<T> StreamLayerMarker<T> {
pub fn new() -> Self {
Self(Default::default())
Expand Down
3 changes: 1 addition & 2 deletions src/integrations/httpz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use serde_json::Value;
use std::{
borrow::Cow,
collections::HashMap,
mem,
sync::{Arc, Mutex},
};

Expand Down Expand Up @@ -202,7 +201,7 @@ impl Request {
pub fn cookies(&mut self) -> Option<CookieJar> {
// 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.
Expand Down
13 changes: 5 additions & 8 deletions src/integrations/tauri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{
collections::{hash_map::DefaultHasher, HashMap},
future::{ready, Ready},
hash::{Hash, Hasher},
marker::PhantomData,
sync::{Arc, Mutex},
};

Expand All @@ -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;

Expand Down Expand Up @@ -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());
}
_ => {}
}
})
})
Expand All @@ -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());
}
_ => {}
}
})
})
Expand Down
8 changes: 3 additions & 5 deletions src/internal/jsonrpc_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ where
result: ResponseInner::Error(err.into()),
})
.await;
return;
}
}
}
Expand Down Expand Up @@ -315,7 +314,6 @@ where
result: ResponseInner::Error(err.into()),
})
.await;
return;
}
}
}
Expand Down Expand Up @@ -409,7 +407,7 @@ where
sender
.send(jsonrpc::Response {
jsonrpc: "2.0",
id: id,
id,
result: ResponseInner::Error(err.into()),
})
.await;
Expand Down Expand Up @@ -479,12 +477,12 @@ where
.await;
}
},
};
}
}
}

// TODO: Can this we removed?
fn to_owned<'a, T>(arc: Cow<'a, Arc<T>>) -> Arc<T> {
fn to_owned<T>(arc: Cow<'_, Arc<T>>) -> Arc<T> {
match arc {
Cow::Borrowed(arc) => arc.to_owned(),
Cow::Owned(arc) => arc,
Expand Down
1 change: 1 addition & 0 deletions src/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down

0 comments on commit 14c6e3a

Please sign in to comment.