Skip to content

Commit e9540b4

Browse files
authored
feat!: Allow http::Middleware trait to return custom errors (#933)
Add `Error` associated type to the `http::Middleware` trait to allow consumers to return a custom error from their `http::Middleware` implementations. This PR also changes all trait/lifetime bounds to put `'static + Send + Sync` first (omitting any that aren't necessary) instead of putting them at the end. Relates to #922
1 parent e5f427f commit e9540b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+438
-342
lines changed

src/api/cli/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ pub mod roadster;
1515
#[non_exhaustive]
1616
pub struct CliState<A, S>
1717
where
18-
S: Clone + Send + Sync + 'static,
18+
S: 'static + Send + Sync + Clone,
1919
AppContext: FromRef<S>,
20-
A: App<S> + Sync + 'static,
20+
A: 'static + Sync + App<S>,
2121
{
2222
pub roadster_cli: RoadsterCli,
2323
pub app_cli: A::Cli,
@@ -32,7 +32,7 @@ where
3232
#[async_trait]
3333
pub trait RunCommand<A, S>
3434
where
35-
S: Clone + Send + Sync + 'static,
35+
S: 'static + Send + Sync + Clone,
3636
AppContext: FromRef<S>,
3737
A: App<S> + Sync,
3838
{
@@ -52,7 +52,7 @@ where
5252

5353
pub(crate) fn parse_cli<A, S, I, T>(args: I) -> RoadsterResult<(RoadsterCli, A::Cli)>
5454
where
55-
S: Clone + Send + Sync + 'static,
55+
S: 'static + Send + Sync + Clone,
5656
AppContext: FromRef<S>,
5757
A: App<S>,
5858
I: IntoIterator<Item = T>,
@@ -99,7 +99,7 @@ where
9999

100100
pub(crate) async fn handle_cli<A, S>(cli: &CliState<A, S>) -> RoadsterResult<bool>
101101
where
102-
S: Clone + Send + Sync + 'static,
102+
S: 'static + Send + Sync + Clone,
103103
AppContext: FromRef<S>,
104104
A: App<S>,
105105
{
@@ -120,7 +120,7 @@ where
120120
#[cfg(test)]
121121
pub struct TestCli<S>
122122
where
123-
S: Clone + Send + Sync + 'static,
123+
S: 'static + Send + Sync + Clone,
124124
AppContext: FromRef<S>,
125125
{
126126
_state: std::marker::PhantomData<S>,
@@ -130,14 +130,14 @@ where
130130
mockall::mock! {
131131
pub TestCli<S>
132132
where
133-
S: Clone + Send + Sync + 'static,
133+
S: 'static + Send + Sync + Clone,
134134
AppContext: FromRef<S>,
135135
{}
136136

137137
#[async_trait]
138138
impl<S> RunCommand<MockApp<S>, S> for TestCli<S>
139139
where
140-
S: Clone + Send + Sync + 'static,
140+
S: 'static + Send + Sync + Clone,
141141
AppContext: FromRef<S>,
142142
{
143143
type Error = std::convert::Infallible;
@@ -147,7 +147,7 @@ mockall::mock! {
147147

148148
impl<S> clap::FromArgMatches for TestCli<S>
149149
where
150-
S: Clone + Send + Sync + 'static,
150+
S: 'static + Send + Sync + Clone,
151151
AppContext: FromRef<S>,
152152
{
153153
fn from_arg_matches(matches: &clap::ArgMatches) -> Result<Self, clap::Error>;
@@ -156,7 +156,7 @@ mockall::mock! {
156156

157157
impl<S> clap::Args for TestCli<S>
158158
where
159-
S: Clone + Send + Sync + 'static,
159+
S: 'static + Send + Sync + Clone,
160160
AppContext: FromRef<S>,
161161
{
162162
fn augment_args(cmd: clap::Command) -> clap::Command;
@@ -165,7 +165,7 @@ mockall::mock! {
165165

166166
impl<S> Clone for TestCli<S>
167167
where
168-
S: Clone + Send + Sync + 'static,
168+
S: 'static + Send + Sync + Clone,
169169
AppContext: FromRef<S>,
170170
{
171171
fn clone(&self) -> Self;

src/api/cli/roadster/health.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct HealthArgs {
2222
#[async_trait]
2323
impl<A, S> RunRoadsterCommand<A, S> for HealthArgs
2424
where
25-
S: Clone + Send + Sync + 'static,
25+
S: 'static + Send + Sync + Clone,
2626
AppContext: FromRef<S>,
2727
A: App<S>,
2828
{

src/api/cli/roadster/list_routes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct ListRoutesArgs {}
1818
#[async_trait]
1919
impl<A, S> RunRoadsterCommand<A, S> for ListRoutesArgs
2020
where
21-
S: Clone + Send + Sync + 'static,
21+
S: 'static + Send + Sync + Clone,
2222
AppContext: FromRef<S>,
2323
A: App<S>,
2424
{

src/api/cli/roadster/migrate.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct MigrateArgs {
2121
#[async_trait]
2222
impl<A, S> RunRoadsterCommand<A, S> for MigrateArgs
2323
where
24-
S: Clone + Send + Sync + 'static,
24+
S: 'static + Send + Sync + Clone,
2525
AppContext: FromRef<S>,
2626
A: App<S>,
2727
{
@@ -47,7 +47,7 @@ pub enum MigrateCommand {
4747
#[async_trait]
4848
impl<A, S> RunRoadsterCommand<A, S> for MigrateCommand
4949
where
50-
S: Clone + Send + Sync + 'static,
50+
S: 'static + Send + Sync + Clone,
5151
AppContext: FromRef<S>,
5252
A: App<S>,
5353
{
@@ -93,7 +93,7 @@ fn is_destructive(command: &MigrateCommand) -> bool {
9393
// Todo: reduce duplication
9494
async fn migrate_up<A, S>(cli: &CliState<A, S>, args: &UpArgs) -> RoadsterResult<()>
9595
where
96-
S: Clone + Send + Sync + 'static,
96+
S: 'static + Send + Sync + Clone,
9797
AppContext: FromRef<S>,
9898
A: App<S>,
9999
{
@@ -121,7 +121,7 @@ where
121121
// Todo: reduce duplication
122122
async fn migrate_down<A, S>(cli: &CliState<A, S>, args: &DownArgs) -> RoadsterResult<()>
123123
where
124-
S: Clone + Send + Sync + 'static,
124+
S: 'static + Send + Sync + Clone,
125125
AppContext: FromRef<S>,
126126
A: App<S>,
127127
{
@@ -148,7 +148,7 @@ where
148148

149149
async fn print_status<A, S>(cli: &CliState<A, S>) -> RoadsterResult<()>
150150
where
151-
S: Clone + Send + Sync + 'static,
151+
S: 'static + Send + Sync + Clone,
152152
AppContext: FromRef<S>,
153153
A: App<S>,
154154
{

src/api/cli/roadster/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub mod print_config;
3131
#[async_trait]
3232
pub(crate) trait RunRoadsterCommand<A, S>
3333
where
34-
S: Clone + Send + Sync + 'static,
34+
S: 'static + Send + Sync + Clone,
3535
AppContext: FromRef<S>,
3636
A: App<S>,
3737
{
@@ -78,7 +78,7 @@ impl RoadsterCli {
7878
#[async_trait]
7979
impl<A, S> RunRoadsterCommand<A, S> for RoadsterCli
8080
where
81-
S: Clone + Send + Sync + 'static,
81+
S: 'static + Send + Sync + Clone,
8282
AppContext: FromRef<S>,
8383
A: App<S>,
8484
{
@@ -104,7 +104,7 @@ pub enum RoadsterCommand {
104104
#[async_trait]
105105
impl<A, S> RunRoadsterCommand<A, S> for RoadsterCommand
106106
where
107-
S: Clone + Send + Sync + 'static,
107+
S: 'static + Send + Sync + Clone,
108108
AppContext: FromRef<S>,
109109
A: App<S>,
110110
{
@@ -125,7 +125,7 @@ pub struct RoadsterArgs {
125125
#[async_trait]
126126
impl<A, S> RunRoadsterCommand<A, S> for RoadsterArgs
127127
where
128-
S: Clone + Send + Sync + 'static,
128+
S: 'static + Send + Sync + Clone,
129129
AppContext: FromRef<S>,
130130
A: App<S>,
131131
{
@@ -137,7 +137,7 @@ where
137137
#[async_trait]
138138
impl<A, S> RunRoadsterCommand<A, S> for RoadsterSubCommand
139139
where
140-
S: Clone + Send + Sync + 'static,
140+
S: 'static + Send + Sync + Clone,
141141
AppContext: FromRef<S>,
142142
A: App<S>,
143143
{

src/api/cli/roadster/open_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use axum_core::extract::FromRef;
1010
#[async_trait]
1111
impl<A, S> RunRoadsterCommand<A, S> for OpenApiArgs
1212
where
13-
S: Clone + Send + Sync + 'static,
13+
S: 'static + Send + Sync + Clone,
1414
AppContext: FromRef<S>,
1515
A: App<S>,
1616
{

src/api/cli/roadster/print_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub enum Format {
3636
#[async_trait]
3737
impl<A, S> RunRoadsterCommand<A, S> for PrintConfigArgs
3838
where
39-
S: Clone + Send + Sync + 'static,
39+
S: 'static + Send + Sync + Clone,
4040
AppContext: FromRef<S>,
4141
A: App<S>,
4242
{

src/api/core/health.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub async fn health_check<S>(
3737
duration: Option<Duration>,
3838
) -> RoadsterResult<HeathCheckResponse>
3939
where
40-
S: Clone + Send + Sync + 'static,
40+
S: 'static + Send + Sync + Clone,
4141
AppContext: FromRef<S>,
4242
{
4343
let context = AppContext::from_ref(state);
@@ -50,7 +50,7 @@ pub(crate) async fn health_check_with_checks<S>(
5050
duration: Option<Duration>,
5151
) -> RoadsterResult<HeathCheckResponse>
5252
where
53-
S: Clone + Send + Sync + 'static,
53+
S: 'static + Send + Sync + Clone,
5454
AppContext: FromRef<S>,
5555
{
5656
if let Some(duration) = duration.as_ref() {

src/api/http/docs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::sync::Arc;
1414
/// This API is only available when using Aide.
1515
pub fn routes<S>(parent: &str, state: &S) -> ApiRouter<S>
1616
where
17-
S: Clone + Send + Sync + 'static,
17+
S: 'static + Send + Sync + Clone,
1818
AppContext: FromRef<S>,
1919
{
2020
let context = AppContext::from_ref(state);

src/api/http/health.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const TAG: &str = "Health";
2525

2626
pub fn routes<S>(parent: &str, state: &S) -> Router<S>
2727
where
28-
S: Clone + Send + Sync + 'static,
28+
S: 'static + Send + Sync + Clone,
2929
AppContext: FromRef<S>,
3030
{
3131
let context = AppContext::from_ref(state);
@@ -40,7 +40,7 @@ where
4040
#[cfg(feature = "open-api")]
4141
pub fn api_routes<S>(parent: &str, state: &S) -> ApiRouter<S>
4242
where
43-
S: Clone + Send + Sync + 'static,
43+
S: 'static + Send + Sync + Clone,
4444
AppContext: FromRef<S>,
4545
{
4646
let context = AppContext::from_ref(state);
@@ -93,7 +93,7 @@ async fn health_get<S>(
9393
Query(query): Query<HeathCheckRequest>,
9494
) -> RoadsterResult<Json<HeathCheckResponse>>
9595
where
96-
S: Clone + Send + Sync + 'static,
96+
S: 'static + Send + Sync + Clone,
9797
AppContext: FromRef<S>,
9898
{
9999
let duration = query

0 commit comments

Comments
 (0)