Skip to content

add function single generic type support#3779

Open
uraneko wants to merge 7 commits intoactix:mainfrom
uraneko:2866
Open

add function single generic type support#3779
uraneko wants to merge 7 commits intoactix:mainfrom
uraneko:2866

Conversation

@uraneko
Copy link
Copy Markdown

@uraneko uraneko commented Sep 26, 2025

PR Type

Other(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.
  • (Team) Label with affected crates and semver status.

Overview

Closes #2866

@github-actions github-actions bot added A-web-codegen project: actix-web-codegen A-web project: actix-web B-semver-patch labels Feb 3, 2026
@JohnTitor JohnTitor added B-semver-major breaking change requiring a major version bump and removed B-semver-patch labels Feb 5, 2026
@JohnTitor
Copy link
Copy Markdown
Member

Thanks for the PR! I've tweaked to support more generics and have better test suite.
But the current implementation has technically breaking change around Default impl although I think the current is one of good form to land.
If you have a good idea here, I'm happy to hear and see it :)

@uraneko
Copy link
Copy Markdown
Author

uraneko commented Mar 8, 2026

Thanks for the tweaks, I think the current pr state looks pretty good.

But the current implementation has technically breaking change around Default impl

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 app.route(...) can still be used with the same syntax, while the method macro + app.service(...) pattern is now extended to support generics by registering service_function::<Generics>::default(). Or is the breaking change around something else?

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())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-web project: actix-web A-web-codegen project: actix-web-codegen B-semver-major breaking change requiring a major version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot infer type for type parameter when defining handler with #[get("/")] and generics

2 participants