Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service trait takes request type parameter #232

Merged
merged 6 commits into from
Dec 27, 2020
Merged

service trait takes request type parameter #232

merged 6 commits into from
Dec 27, 2020

Conversation

robjtede
Copy link
Member

@robjtede robjtede commented Dec 25, 2020

PR Type

Improvement

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the latest stable rustfmt

Overview

It's advantageous to accept multiple request types for a given service. I believe this will simplify some of the complex types and handling in actix-web http1/http2 request dispatching.

Obviously massive breaking change to actix-service. Other breaking changes include:

actix-connect:

  • new_connector()
  • new_connector_factory()
  • default_connector()
  • default_connector_factory()

actix-server:

  • ServiceFactory
  • ServiceRuntime::service()

@robjtede
Copy link
Member Author

I'll wait on #229 so this PR is smaller.

@robjtede robjtede marked this pull request as draft December 25, 2020 11:53
@robjtede robjtede marked this pull request as ready for review December 27, 2020 02:17
@robjtede robjtede requested review from a team December 27, 2020 02:28
Copy link
Contributor

@fakeshadow fakeshadow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

actix-service/src/boxed.rs Outdated Show resolved Hide resolved
actix-service/src/boxed.rs Outdated Show resolved Hide resolved
f: F,
) -> FnServiceConfig<F, Fut, Cfg, Srv, Err>
) -> FnServiceConfig<F, Fut, Cfg, Srv, Req, Err>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe FnServiceConfig<F, Fut, Cfg, Req> would be enough type. Srv and Err type are actuall associate types for Fut so they can be unconstraint.

Comment on lines +243 to 251
pub struct FnServiceConfig<F, Fut, Cfg, Srv, Req, Err>
where
F: Fn(Cfg) -> Fut,
Fut: Future<Output = Result<Srv, Err>>,
Srv: Service,
Srv: Service<Req>,
{
f: F,
_t: PhantomData<(Fut, Cfg, Srv, Err)>,
_t: PhantomData<(Fut, Cfg, Req, Srv, Err)>,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like previous comment.

pub struct FnServiceConfig<F, Fut, Cfg, Req>
where
    F: Fn(Cfg) -> Fut,
    Fut: Future,
{
    f: F,
    _t: PhantomData<(Fut, Cfg, Req)>,
}

}

impl<F, Fut, Cfg, Srv, Err> FnServiceConfig<F, Fut, Cfg, Srv, Err>
impl<F, Fut, Cfg, Srv, Req, Err> FnServiceConfig<F, Fut, Cfg, Srv, Req, Err>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl<F, Fut, Cfg, Srv, Req, Err> FnServiceConfig<F, Fut, Cfg, Req>

{
fn new(f: F) -> Self {
FnServiceConfig { f, _t: PhantomData }
}
}

impl<F, Fut, Cfg, Srv, Err> Clone for FnServiceConfig<F, Fut, Cfg, Srv, Err>
impl<F, Fut, Cfg, Srv, Req, Err> Clone for FnServiceConfig<F, Fut, Cfg, Srv, Req, Err>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl<F, Fut, Cfg, Srv, Req, Err> Clone for FnServiceConfig<F, Fut, Cfg, Req>

@@ -275,13 +275,13 @@ where
}
}

impl<F, Fut, Cfg, Srv, Err> ServiceFactory for FnServiceConfig<F, Fut, Cfg, Srv, Err>
impl<F, Fut, Cfg, Srv, Req, Err> ServiceFactory<Req>
for FnServiceConfig<F, Fut, Cfg, Srv, Req, Err>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl<F, Fut, Cfg, Srv, Req, Err> ServiceFactory
for FnServiceConfig<F, Fut, Cfg, Req>

@robjtede robjtede merged commit 3ab8c3e into master Dec 27, 2020
@robjtede robjtede deleted the svc branch December 27, 2020 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants