Skip to content

Commit

Permalink
Clippy cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Oct 9, 2023
1 parent 37ba9e2 commit 8eac5ab
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 169 deletions.
42 changes: 0 additions & 42 deletions crates/core/src/body/map.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/core/src/body/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod body;
mod map;
mod once;

pub use body::*;
pub(crate) use map::*;
pub(crate) use once::*;
17 changes: 14 additions & 3 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ pub trait IntoResolverError: Serialize + Type + std::error::Error {
Self: Sized,
{
ResolverError {
value: serde_json::to_value(&self).unwrap_or_default(),
// TODO: Error handling
value: serde_json::to_value(&self).unwrap(),
message: self.to_string(),
}
}
Expand Down Expand Up @@ -123,8 +124,18 @@ impl From<ExecError> for ProcedureError {
cause: None,
},
ExecError::Resolver(err) => return err.into(),
ExecError::ErrSubscriptionNotFound => todo!(),
ExecError::ErrSubscriptionAlreadyClosed => todo!(),
// ExecError::ErrSubscriptionNotFound => Error {
// code: ErrorCode::InternalServerError,
// message: "error a procedure returned an empty stream".into(),
// cause: None,
// },
// ExecError::ErrSubscriptionAlreadyClosed => Error {
// code: ErrorCode::InternalServerError,
// message: "error subscription was already closed".into(),
// cause: None,
// },
// TODO: Sort out this panic
_ => todo!(),
})
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/exec/arc_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use serde_json::Value;
use crate::{
body::Body,
middleware::{ProcedureKind, RequestContext},
procedure_store::ProcedureTodo,
router_builder::ProcedureMap,
Router,
};
Expand Down
21 changes: 7 additions & 14 deletions crates/core/src/exec/connection.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::{
collections::HashMap,
future::Future,
marker::PhantomData,
pin::{pin, Pin},
sync::Arc,
task::{Context, Poll},
time::{Duration, Instant},
};

Expand All @@ -13,27 +10,22 @@ use futures::{
mpsc::{self, UnboundedReceiver, UnboundedSender},
oneshot,
},
future::{Either, OptionFuture},
pin_mut, ready,
stream::{self, Fuse, FusedStream, FuturesUnordered},
future::OptionFuture,
pin_mut,
stream::{self, FusedStream, FuturesUnordered},
FutureExt, Sink, SinkExt, Stream, StreamExt,
};
use pin_project_lite::pin_project;
use serde_json::Value;
use streamunordered::{StreamUnordered, StreamYield};

use super::{ExecutorResult, IncomingMessage, Request, Requests, Response, Task};
use crate::{
exec,
util::{PinnedOption, PinnedOptionProj},
AsyncRuntime, Router,
};
use super::{ExecutorResult, IncomingMessage, Request, Response, Task};
use crate::{exec, AsyncRuntime, Router};

// Time to wait for more messages before sending them over the websocket connection.
// This batch is mostly designed to reduce the impact of duplicate subscriptions a bit
// as sending them together should help us utilise transport layer compression.
const BATCH_TIMEOUT: Duration = Duration::from_millis(5);

// TODO: I don't like this
pub(crate) struct TaskShutdown {
stream_id: usize,
tx: oneshot::Sender<usize>,
Expand Down Expand Up @@ -106,6 +98,7 @@ fn batch_unbounded<R: AsyncRuntime, T>(
'batch: loop {
let timer = R::sleep_util(Instant::now() + BATCH_TIMEOUT).fuse();

#[allow(clippy::never_loop)]
'timer: loop {
pin_mut!(timer);

Expand Down
24 changes: 3 additions & 21 deletions crates/core/src/exec/execute.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
use std::{
borrow::Cow,
collections::{HashMap, HashSet},
convert::Infallible,
fmt,
future::{Future, Ready},
marker::PhantomData,
ops::{Deref, DerefMut},
pin::Pin,
sync::{Arc, Mutex},
task::{Context, Poll, Waker},
};

use futures::{channel::oneshot, stream::FuturesUnordered, Stream, StreamExt};

use serde_json::Value;
use std::{pin::Pin, sync::Arc};

use crate::{
body::Body,
Expand All @@ -23,14 +8,10 @@ use crate::{
request_future::RequestFuture,
Request, Response, ResponseInner, Task,
},
layer::FutureValueOrStream,
middleware::{ProcedureKind, RequestContext},
procedure_store::ProcedureTodo,
router_builder::ProcedureMap,
Router,
};

use super::{task, Connection, RequestData};
use super::{task, Connection};

/// TODO
///
Expand All @@ -56,6 +37,7 @@ impl<TCtx: Send + 'static> Router<TCtx> {
self: Arc<Self>,
ctx: TCtx,
req: Request,
// TODO: Can the executor be decoupled from the connection???
conn: Option<&mut Connection<TCtx>>,
) -> Option<ExecutorResult> {
// TODO
Expand Down
10 changes: 1 addition & 9 deletions crates/core/src/exec/request_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@ use std::{
fmt,
future::Future,
pin::Pin,
sync::Arc,
task::{Context, Poll},
};

use futures::{ready, Stream};
use pin_project_lite::pin_project;
use serde_json::Value;

use crate::{
body::Body,
error::ExecError,
exec::{self, Response, ResponseInner},
middleware::RequestContext,
util::{PinnedOption, PinnedOptionProj},
Router,
exec::{Response, ResponseInner},
};

use super::arc_ref::ArcRef;
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/exec/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl Stream for Task {
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Option<Self::Item>> {
match &self.status {
#[allow(clippy::panic)]
Status::DoNotPoll => {
#[cfg(debug_assertions)]
panic!("`StreamWrapper` polled after completion")
Expand Down
9 changes: 2 additions & 7 deletions crates/core/src/middleware/mw_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ use serde_json::Value;
use super::{Executable2Placeholder, MwResultWithCtx};

pub fn new_mw_ctx(input: serde_json::Value, req: RequestContext) -> MiddlewareContext {
MiddlewareContext {
input,
req,
_priv: (),
}
MiddlewareContext { input, req }
}

#[non_exhaustive]
pub struct MiddlewareContext {
pub input: Value,
pub req: RequestContext,
// Prevents downstream user constructing type
_priv: (),
}

impl MiddlewareContext {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/procedure_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn never() -> DataType {
},
&[],
)
.unwrap()
.expect("rspc: error exporting `never`")
}

impl ProcedureDef {
Expand All @@ -88,7 +88,7 @@ impl ProcedureDef {
},
&[],
)? {
DataType::Tuple(TupleType::Named { fields, .. }) if fields.len() == 0 => never(),
DataType::Tuple(TupleType::Named { fields, .. }) if fields.is_empty() => never(),
t => t,
},
result: TResult::reference(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ where
Some(dt) => {
if let Some(ext) = dt.ext() {
if let Some((existing_sid, existing_impl_location)) =
map.insert(dt.name(), (sid, ext.impl_location().clone()))
map.insert(dt.name(), (sid, *ext.impl_location()))
{
if existing_sid != sid {
return Err(ExportError::TsExportErr(
TsExportError::DuplicateTypeName(
dt.name().clone(),
ext.impl_location().clone(),
*ext.impl_location(),
existing_impl_location,
),
));
Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ impl<T> From<T> for PinnedOption<T> {
}
}

// TODO: Avoid need for manually expanding the `pin_project` macro
/* The `cargo expand` output for `pin_project!` so that we can make `PinnedOptionProj` public */
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::unknown_clippy_lints)]
#[allow(clippy::unknown_lints)]
#[allow(clippy::mut_mut)]
#[allow(clippy::redundant_pub_crate)]
#[allow(clippy::ref_option_ref)]
Expand All @@ -34,7 +35,7 @@ where
None,
}
#[allow(single_use_lifetimes)]
#[allow(clippy::unknown_clippy_lints)]
#[allow(clippy::unknown_lints)]
#[allow(clippy::used_underscore_binding)]
#[allow(unsafe_code)] // <- Custom
#[allow(warnings)] // <- Custom
Expand Down
14 changes: 11 additions & 3 deletions crates/httpz/src/httpz_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
};

use rspc_core::{
exec::{self, Connection, ExecutorResult},
exec::{self, ExecutorResult},
Router,
};

Expand Down Expand Up @@ -127,7 +127,11 @@ where
Some(res) => match res {
ExecutorResult::Future(fut) => fut.await,
ExecutorResult::Response(response) => response,
ExecutorResult::Task(task) => todo!(),
#[allow(clippy::panic)]
ExecutorResult::Task(_) => {
#[cfg(debug_assertions)]
panic!("rspc: unexpected HTTP endpoint returned 'Task'");
}
},
None => unreachable!(
"Executor will only return none for a 'stopSubscription' event which is impossible here"
Expand Down Expand Up @@ -215,7 +219,11 @@ where
ExecutorResult::Response(resp) => {
responses.push(resp);
}
ExecutorResult::Task(task) => todo!(),
#[allow(clippy::panic)]
ExecutorResult::Task(_) => {
#[cfg(debug_assertions)]
panic!("rspc: unexpected HTTP endpoint returned 'Task'");
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions crates/httpz/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
//! Integrate rspc with a http server so it can be accessed from your frontend.
//!
//! This is done through [httpz](https://github.com/oscartbeaumont/httpz).
#![warn(
clippy::all,
clippy::cargo,
clippy::unwrap_used,
clippy::panic,
clippy::todo,
clippy::panic_in_result_fn,
// missing_docs
)]
#![forbid(unsafe_code)]
#![allow(clippy::module_inception)]
#![cfg_attr(docsrs, feature(doc_cfg))]

mod cookie_jar;
mod extractors;
Expand Down
12 changes: 12 additions & 0 deletions crates/tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
//! Access rspc via the Tauri IPC bridge.
#![warn(
clippy::all,
clippy::cargo,
clippy::unwrap_used,
clippy::panic,
clippy::todo,
clippy::panic_in_result_fn,
// missing_docs
)]
#![forbid(unsafe_code)]
#![allow(clippy::module_inception)]
#![cfg_attr(docsrs, feature(doc_cfg))]

use std::{
collections::{hash_map::DefaultHasher, HashMap},
Expand Down
6 changes: 3 additions & 3 deletions examples/axum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ async fn main() {
.procedure("echo", R.query(|_, v: String| Ok(v)))
.procedure(
"error",
R.query(|_, _: ()| Err(Error("Something went wrong".into())) as Result<String, _>),
R.query(|_, _: ()| Err(Error("Something went wrong")) as Result<String, _>),
)
.procedure(
"error",
R.mutation(|_, _: ()| Err(Error("Something went wrong".into())) as Result<String, _>),
R.mutation(|_, _: ()| Err(Error("Something went wrong")) as Result<String, _>),
)
.procedure(
"transformMe",
Expand Down Expand Up @@ -100,7 +100,7 @@ async fn main() {
yield Ok("ping".to_string());
sleep(Duration::from_secs(1)).await;
}
yield Err(Error("Something went wrong".into()));
yield Err(Error("Something went wrong"));
}
}),
)
Expand Down
Loading

0 comments on commit 8eac5ab

Please sign in to comment.