Replies: 2 comments
-
I don't fully understand what you're doing, but I can tell you why you're getting that error: |
Beta Was this translation helpful? Give feedback.
0 replies
-
Awesome, that helps me, even though I've went and tried to attack this problem from a differen angle. I rewrote my code like this:
Which compiles, and it does exactly do what I want. The hint was appreciated! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
Hey,
I'm pretty new to using Axum, and I'm trying to rewrite my application to use it. I was using Rocket, but it doesn't feel right to me to have to write the same logic to load the DB data in each and every handler that uses the same URL prefix.
I had the idea of constructing the routes in such a way that a model/record gets loaded and is available in all sub-routes of the form: /actor/:hash/*
Where * will be all the subroutes which are yet to be determined.
So that I don't have to load the same model again and again in all the handlers that start with /actor/:hash
So what I did is this:
And then in the
actor
module:So, this doesn't compile, and it gives me this error:
The error message is a bit hard to digest, but apparently the
tower::Service
trait isn't automatically implemented anymore. But if I remove the state argument fromindex
, it does compile.Now when I try to use the extension, it does compile, and it does work, I get the correct actor record into the index handler when it gets invoked.
So I guess the first question is: Why can't the index function for this (sub-)router take state, and then still be a service?
And second question: Is there maybe just a better way to do what I'm trying to accomplish here?
Thanks a lot in advance!
axum version
0.7.5
Beta Was this translation helpful? Give feedback.
All reactions