Skip to content

Commit

Permalink
Add alias for complex type
Browse files Browse the repository at this point in the history
  • Loading branch information
spencewenski committed Oct 21, 2024
1 parent 591867c commit af64e60
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/service/http/initializer/any.rs
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ use axum::Router;
use axum_core::extract::FromRef;
use typed_builder::TypedBuilder;

type ApplyFn<S> = Box<dyn Fn(Router, &S) -> RoadsterResult<Router> + Send>;

#[derive(TypedBuilder)]
pub struct AnyInitializer<S>
where
@@ -20,7 +22,7 @@ where
#[builder(default, setter(strip_option))]
stage: Option<Stage>,
#[builder(setter(transform = |a: impl Fn(Router, &S) -> RoadsterResult<Router> + Send + 'static| to_box_fn(a) ))]
apply: Box<dyn Fn(Router, &S) -> RoadsterResult<Router> + Send>,
apply: ApplyFn<S>,
}

#[derive(Default)]
@@ -33,9 +35,7 @@ pub enum Stage {
BeforeServe,
}

fn to_box_fn<S>(
p: impl Fn(Router, &S) -> RoadsterResult<Router> + Send + 'static,
) -> Box<dyn Fn(Router, &S) -> RoadsterResult<Router> + Send> {
fn to_box_fn<S>(p: impl Fn(Router, &S) -> RoadsterResult<Router> + Send + 'static) -> ApplyFn<S> {
Box::new(p)
}

8 changes: 4 additions & 4 deletions src/service/http/middleware/any.rs
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ use axum::Router;
use axum_core::extract::FromRef;
use typed_builder::TypedBuilder;

type ApplyFn<S> = Box<dyn Fn(Router, &S) -> RoadsterResult<Router> + Send>;

#[derive(TypedBuilder)]
#[non_exhaustive]
pub struct AnyMiddleware<S>
@@ -19,12 +21,10 @@ where
#[builder(default, setter(strip_option))]
priority: Option<i32>,
#[builder(setter(transform = |a: impl Fn(Router, &S) -> RoadsterResult<Router> + Send + 'static| to_box_fn(a) ))]
apply: Box<dyn Fn(Router, &S) -> RoadsterResult<Router> + Send>,
apply: ApplyFn<S>,
}

fn to_box_fn<S>(
p: impl Fn(Router, &S) -> RoadsterResult<Router> + Send + 'static,
) -> Box<dyn Fn(Router, &S) -> RoadsterResult<Router> + Send> {
fn to_box_fn<S>(p: impl Fn(Router, &S) -> RoadsterResult<Router> + Send + 'static) -> ApplyFn<S> {
Box::new(p)
}

0 comments on commit af64e60

Please sign in to comment.