Compare commits

...

11 Commits

Author SHA1 Message Date
urane d2385de5a2
Merge f4118bb01f into afd53045d4 2026-01-09 22:42:33 +08:00
dependabot[bot] afd53045d4
build(deps): bump taiki-e/cache-cargo-install-action from 2.3.1 to 3.0.0 (#3867)
Bumps [taiki-e/cache-cargo-install-action](https://github.com/taiki-e/cache-cargo-install-action) from 2.3.1 to 3.0.0.
- [Release notes](https://github.com/taiki-e/cache-cargo-install-action/releases)
- [Changelog](https://github.com/taiki-e/cache-cargo-install-action/blob/main/CHANGELOG.md)
- [Commits](7447f04c51...25ef989260)

---
updated-dependencies:
- dependency-name: taiki-e/cache-cargo-install-action
  dependency-version: 3.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-06 22:08:06 +00:00
dependabot[bot] d0b9f46e50
build(deps): bump tokio-util from 0.7.17 to 0.7.18 (#3871)
Bumps [tokio-util](https://github.com/tokio-rs/tokio) from 0.7.17 to 0.7.18.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-util-0.7.17...tokio-util-0.7.18)

---
updated-dependencies:
- dependency-name: tokio-util
  dependency-version: 0.7.18
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-06 22:08:00 +00:00
dependabot[bot] e04b8d548d
build(deps): bump tokio from 1.48.0 to 1.49.0 (#3872)
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.48.0 to 1.49.0.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.48.0...tokio-1.49.0)

---
updated-dependencies:
- dependency-name: tokio
  dependency-version: 1.49.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-06 22:07:57 +00:00
dependabot[bot] 12db2a4d30
build(deps): bump tokio-stream from 0.1.17 to 0.1.18 (#3869)
Bumps [tokio-stream](https://github.com/tokio-rs/tokio) from 0.1.17 to 0.1.18.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-stream-0.1.17...tokio-stream-0.1.18)

---
updated-dependencies:
- dependency-name: tokio-stream
  dependency-version: 0.1.18
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-05 21:23:55 +00:00
dependabot[bot] d2a2c15ef1
build(deps): bump codecov/codecov-action from 5.5.1 to 5.5.2 (#3856)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.5.1 to 5.5.2.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](5a1091511a...671740ac38)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-version: 5.5.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-05 21:08:09 +00:00
dependabot[bot] 9b25a18383
build(deps): bump proc-macro2 from 1.0.103 to 1.0.104 (#3870)
Bumps [proc-macro2](https://github.com/dtolnay/proc-macro2) from 1.0.103 to 1.0.104.
- [Release notes](https://github.com/dtolnay/proc-macro2/releases)
- [Commits](https://github.com/dtolnay/proc-macro2/compare/1.0.103...1.0.104)

---
updated-dependencies:
- dependency-name: proc-macro2
  dependency-version: 1.0.104
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-05 21:06:24 +00:00
dependabot[bot] 564b364638
build(deps): bump taiki-e/install-action from 2.65.6 to 2.65.12 (#3868)
Bumps [taiki-e/install-action](https://github.com/taiki-e/install-action) from 2.65.6 to 2.65.12.
- [Release notes](https://github.com/taiki-e/install-action/releases)
- [Changelog](https://github.com/taiki-e/install-action/blob/main/CHANGELOG.md)
- [Commits](28a9d316db...cc33365ec7)

---
updated-dependencies:
- dependency-name: taiki-e/install-action
  dependency-version: 2.65.12
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-05 21:04:28 +00:00
urane f4118bb01f
Merge branch 'master' into 2866 2025-09-26 08:38:43 +01:00
uraneko 89527c5ec5 resolve conflict (removes line added by mistake) 2025-09-26 08:36:30 +01:00
uraneko 390555bdb6 add function single generic type support 2025-09-26 07:26:14 +01:00
8 changed files with 146 additions and 43 deletions

View File

@ -49,7 +49,7 @@ jobs:
toolchain: ${{ matrix.version.version }}
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
uses: taiki-e/install-action@28a9d316db64b78a951f3f8587a5d08cc97ad8eb # v2.65.6
uses: taiki-e/install-action@cc33365ec7e3350bc47bf935f247582cc6f68344 # v2.65.12
with:
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
@ -83,7 +83,7 @@ jobs:
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
- name: Install just, cargo-hack
uses: taiki-e/install-action@28a9d316db64b78a951f3f8587a5d08cc97ad8eb # v2.65.6
uses: taiki-e/install-action@cc33365ec7e3350bc47bf935f247582cc6f68344 # v2.65.12
with:
tool: just,cargo-hack

View File

@ -64,7 +64,7 @@ jobs:
toolchain: ${{ matrix.version.version }}
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
uses: taiki-e/install-action@28a9d316db64b78a951f3f8587a5d08cc97ad8eb # v2.65.6
uses: taiki-e/install-action@cc33365ec7e3350bc47bf935f247582cc6f68344 # v2.65.12
with:
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
@ -117,7 +117,7 @@ jobs:
toolchain: nightly
- name: Install just
uses: taiki-e/install-action@28a9d316db64b78a951f3f8587a5d08cc97ad8eb # v2.65.6
uses: taiki-e/install-action@cc33365ec7e3350bc47bf935f247582cc6f68344 # v2.65.12
with:
tool: just

View File

@ -24,7 +24,7 @@ jobs:
components: llvm-tools
- name: Install just, cargo-llvm-cov, cargo-nextest
uses: taiki-e/install-action@28a9d316db64b78a951f3f8587a5d08cc97ad8eb # v2.65.6
uses: taiki-e/install-action@cc33365ec7e3350bc47bf935f247582cc6f68344 # v2.65.12
with:
tool: just,cargo-llvm-cov,cargo-nextest
@ -32,7 +32,7 @@ jobs:
run: just test-coverage-codecov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
with:
files: codecov.json
fail_ci_if_error: true

View File

@ -77,12 +77,12 @@ jobs:
toolchain: ${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
- name: Install just
uses: taiki-e/install-action@28a9d316db64b78a951f3f8587a5d08cc97ad8eb # v2.65.6
uses: taiki-e/install-action@cc33365ec7e3350bc47bf935f247582cc6f68344 # v2.65.12
with:
tool: just
- name: Install cargo-check-external-types
uses: taiki-e/cache-cargo-install-action@7447f04c51f2ba27ca35e7f1e28fab848c5b3ba7 # v2.3.1
uses: taiki-e/cache-cargo-install-action@25ef9892608d184944df486ae09ffae168b3cda3 # v3.0.0
with:
tool: cargo-check-external-types

16
Cargo.lock generated
View File

@ -2262,9 +2262,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.103"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
checksum = "9695f8df41bb4f3d222c95a67532365f569318332d03d5f3f67f37b20e6ebdf0"
dependencies = [
"unicode-ident",
]
@ -3033,9 +3033,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.48.0"
version = "1.49.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408"
checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86"
dependencies = [
"bytes",
"libc",
@ -3114,9 +3114,9 @@ dependencies = [
[[package]]
name = "tokio-stream"
version = "0.1.17"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047"
checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70"
dependencies = [
"futures-core",
"pin-project-lite",
@ -3140,9 +3140,9 @@ dependencies = [
[[package]]
name = "tokio-util"
version = "0.7.17"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2efa149fe76073d6e8fd97ef4f4eca7b67f599660115591483572e406e165594"
checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098"
dependencies = [
"bytes",
"futures-core",

View File

@ -328,6 +328,9 @@ pub struct Route {
/// Name of the handler function being annotated.
name: syn::Ident,
/// function generic
type_generic: Option<syn::TypeParam>,
/// Args passed to routing macro.
///
/// When using `#[routes]`, this will contain args for each specific routing macro.
@ -344,6 +347,13 @@ impl Route {
pub fn new(args: RouteArgs, ast: syn::ItemFn, method: Option<MethodType>) -> syn::Result<Self> {
let name = ast.sig.ident.clone();
let generics = ast.sig.generics.params.clone();
let type_generic = if let Some(syn::GenericParam::Type(ty)) = generics.into_iter().next() {
Some(ty)
} else {
None
};
// Try and pull out the doc comments so that we can reapply them to the generated struct.
// Note that multi line doc comments are converted to multiple doc attributes.
let doc_attributes = ast
@ -370,6 +380,7 @@ impl Route {
}
Ok(Self {
type_generic,
name,
args: vec![args],
ast,
@ -380,6 +391,13 @@ impl Route {
fn multiple(args: Vec<Args>, ast: syn::ItemFn) -> syn::Result<Self> {
let name = ast.sig.ident.clone();
let generics = ast.sig.generics.params.clone();
let type_generic = if let Some(syn::GenericParam::Type(ty)) = generics.into_iter().next() {
Some(ty)
} else {
None
};
// Try and pull out the doc comments so that we can reapply them to the generated struct.
// Note that multi line doc comments are converted to multiple doc attributes.
let doc_attributes = ast
@ -398,6 +416,7 @@ impl Route {
Ok(Self {
name,
type_generic,
args,
ast,
doc_attributes,
@ -409,6 +428,7 @@ impl ToTokens for Route {
fn to_tokens(&self, output: &mut TokenStream2) {
let Self {
name,
type_generic,
ast,
args,
doc_attributes,
@ -421,6 +441,17 @@ impl ToTokens for Route {
#[cfg(feature = "compat-routing-macros-force-pub")]
let vis = syn::Visibility::Public(<Token![pub]>::default());
let (struct_generic, trait_generic, impl_type_generic) =
if let Some(syn::TypeParam { ident, bounds, .. }) = type_generic {
(
Some(quote! { <#ident> (core::marker::PhantomData<T>) }),
Some(quote! { <#ident: #bounds + 'static> }),
Some(quote! { <#ident> }),
)
} else {
(None, None, None)
};
let registrations: TokenStream2 = args
.iter()
.map(|args| {
@ -453,13 +484,19 @@ impl ToTokens for Route {
}
};
let type_generic = if let Some(syn::TypeParam { ident, .. }) = type_generic {
Some(quote! { ::<#ident> })
} else {
None
};
quote! {
let __resource = ::actix_web::Resource::new(#path)
.name(#resource_name)
#method_guards
#(.guard(::actix_web::guard::fn_guard(#guards)))*
#(.wrap(#wrappers))*
.to(#name);
.to(#name #type_generic);
::actix_web::dev::HttpServiceFactory::register(__resource, __config);
}
})
@ -468,9 +505,11 @@ impl ToTokens for Route {
let stream = quote! {
#(#doc_attributes)*
#[allow(non_camel_case_types)]
#vis struct #name;
#[derive(Default)]
#vis struct #name #struct_generic;
impl ::actix_web::dev::HttpServiceFactory for #name {
impl #trait_generic ::actix_web::dev::HttpServiceFactory for #name #impl_type_generic
{
fn register(self, __config: &mut actix_web::dev::AppService) {
#ast
#registrations

View File

@ -5,10 +5,10 @@ description = "Actix Web is a powerful, pragmatic, and extremely fast web framew
authors = ["Nikolay Kim <fafhrd91@gmail.com>", "Rob Ede <robjtede@icloud.com>"]
keywords = ["actix", "http", "web", "framework", "async"]
categories = [
"network-programming",
"asynchronous",
"web-programming::http-server",
"web-programming::websocket",
"network-programming",
"asynchronous",
"web-programming::http-server",
"web-programming::websocket",
]
homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-web"
@ -18,17 +18,17 @@ rust-version.workspace = true
[package.metadata.docs.rs]
features = [
"macros",
"openssl",
"rustls-0_20",
"rustls-0_21",
"rustls-0_22",
"rustls-0_23",
"compress-brotli",
"compress-gzip",
"compress-zstd",
"cookies",
"secure-cookies",
"macros",
"openssl",
"rustls-0_20",
"rustls-0_21",
"rustls-0_22",
"rustls-0_23",
"compress-brotli",
"compress-gzip",
"compress-zstd",
"cookies",
"secure-cookies",
]
[package.metadata.cargo_check_external_types]
@ -58,15 +58,15 @@ allowed_external_types = [
[features]
default = [
"macros",
"compress-brotli",
"compress-gzip",
"compress-zstd",
"cookies",
"http2",
"unicode",
"compat",
"ws",
"macros",
"compress-brotli",
"compress-gzip",
"compress-zstd",
"cookies",
"http2",
"unicode",
"compat",
"ws",
]
# Brotli algorithm content-encoding support
@ -203,6 +203,10 @@ required-features = ["compress-brotli", "compress-gzip", "compress-zstd"]
name = "basic"
required-features = ["compress-gzip"]
[[example]]
name = "issue"
path = "examples/2866.rs"
[[example]]
name = "uds"
required-features = ["compress-gzip"]

View File

@ -0,0 +1,60 @@
use actix_web::{
dev::Server,
get,
web::{self, Data},
App, HttpServer, Responder,
};
use serde::Serialize;
#[derive(Debug, Serialize, Clone, Copy)]
pub struct User {
id: u64,
}
pub trait UserRepository {
fn get_user(&self) -> User;
}
#[derive(Clone)]
struct UserClient;
impl UserRepository for UserClient {
fn get_user(&self) -> User {
User { id: 99 }
}
}
// when uncommenting following the line, the type checking is unaccepted
// because of cannot infer type parameter T
#[get("/")]
async fn index<T: UserRepository>(client: web::Data<T>) -> impl Responder {
let user = client.into_inner().get_user();
web::Json(user)
}
#[get("hello/{who}")]
async fn hello(who: web::Path<String>) -> impl Responder {
format!("<h1>hello {who}</h1>")
}
pub fn create_server<T: UserRepository + Send + Sync + 'static + Clone>(
search: T,
) -> Result<Server, std::io::Error> {
let server = HttpServer::new(move || {
App::new()
.app_data(Data::new(search.clone()))
// .route("/", web::get().to(index::<T>))
.service(index::<T>(core::marker::PhantomData::<T>))
.service(hello)
})
.bind("127.0.0.1:8080")?
.run();
Ok(server)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
println!("\x1b[1;2;36mserving on http://localhost:8080\x1b[0m");
let user_client = UserClient;
create_server(user_client).unwrap().await
}