Handler trait not satisfied for some handlers despite identical signatures #3557
-
Bug ReportVersionPlatformCrates
DescriptionShort summary: Some handlers with identical signatures to working handlers fail to satisfy the I tried this code: // Working handler (compiles successfully)
// In handlers/module_a.rs
pub async fn create_resource_a(
State(state): State<crate::AppState>,
Json(request): Json<CreateResourceARequest>,
) -> Result<Json<ApiResponse<ResourceAResponse>>, Error> {
// ... implementation
}
// In server.rs
.route("/api/v1/resources-a", post(create_resource_a).get(list_resources_a))
// Failing handler (identical signature, fails to compile)
// In handlers/module_b.rs
pub async fn create_resource_b(
State(state): State<crate::AppState>,
Json(request): Json<CreateResourceBRequest>,
) -> Result<Json<ApiResponse<ResourceBResponse>>, Error> {
// ... implementation
}
// In server.rs
.route("/api/v1/resources-b", post(create_resource_b).get(list_resources_b))I expected to see this happen: Both handlers should compile successfully since they have identical function signatures and follow the same pattern. Instead, this happened: The second handler fails with: Additional observations:
Request/Response Types: // Working handler request type
#[derive(Debug, Deserialize)]
pub struct CreateResourceARequest {
pub name: String,
pub items: Vec<Item>,
pub metadata: HashMap<String, String>,
}
// Failing handler request type
#[derive(Debug, Deserialize)]
pub struct CreateResourceBRequest {
pub id: Option<String>,
pub name: String,
pub description: Option<String>,
pub nested: Option<NestedRequest>,
pub json_data: Option<serde_json::Value>,
pub tags: Option<Vec<String>>,
}Attempted workarounds (all failed):
Environment:
Questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Have you tried the |
Beta Was this translation helpful? Give feedback.
-
|
If it's not the signature, your async fn returns a You may have to comment out the problematic |
Beta Was this translation helpful? Give feedback.
Have you tried the
#[debug_handler]macro that should give better compilation errors?https://docs.rs/axum/latest/axum/attr.debug_handler.html