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

Hi, do you know how to make a function returning a tower service builder? #1

Open
HaoliangXu opened this issue May 7, 2023 · 2 comments

Comments

@HaoliangXu
Copy link

https://github.com/SaadiSave/zero2prod/blob/main/src/startup.rs
in this file, I feel that putting this trunk of code in Axum runner function is to noisy, makes it hard to read, so I like the idea of leaving the service builder in another function
but making another function has its own problem, how to put the right return type on the function signature?

@SaadiSave
Copy link
Owner

You can return the ServiceBuilder from the function. The return type should be something like impl Service<...>.

@HaoliangXu
Copy link
Author

I ended up with this mess as the return type:

ServiceBuilder<
    Stack<
        PropagateRequestIdLayer,
        Stack<
            TraceLayer<SharedClassifier<ServerErrorsAsFailures>>,
            Stack<SetRequestIdLayer<MakeRequestUuid>, Identity>,
        >,
    >,
>

don't know whether there's any way better than this

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

No branches or pull requests

2 participants