add function single generic type support#3779
Conversation
|
Thanks for the PR! I've tweaked to support more generics and have better test suite. |
|
Thanks for the tweaks, I think the current pr state looks pretty good.
I'm not very familiar with the code base, so I may be missing something obvious, but, what's the technically breaking change? My understanding is that Could you show me an example user code that would break due to this change? By the way. should I add a function to the test file to clarify that lifetimes are also supported? Something like this: // actix-web-codegen/tests/trybuild/route-generic-ok.rs
- trait UserRepository {
- fn get_user(&self) -> u64;
- }
- impl UserRepository for UserClient {
- fn get_user(&self) -> u64 {
- 99
- }
- }
+ trait UserRepository {
+ fn get_user(&self) -> &str;
+ }
+ impl UserRepository for UserClient {
+ fn get_user(&self) -> &str {
+ "99"
+ }
+ }
//...
+ #[get("/lifetime")]
+ async fn with_lifetime<'a, T>(client: web::Data<&'a T>) -> &'a str
+ where
+ T: UserRepository + Send + Sync + 'static,
+ {
+ client.get_ref().get_user()
+ }
//...
+ .app_data(web::Data::new(&UserClient))
+ .service(with_lifetime::<UserClient>::default()) |
PR Type
Other(improvement)
PR Checklist
Overview
Closes #2866