Skip to content

[BUG] CorsLayer does not implement MiddlewareLayer trait #11

@Tuntii

Description

@Tuntii

RustAPI Version

0.1.7

Rust Version

1.75.0

Operating System

Windows

Description

CorsLayer cannot be used with layer() method because it doesn't implement the MiddlewareLayer trait. This results in a trait bound error during compilation.

Steps to Reproduce

  1. Use rustapi_rs:: prelude::* and std::time::Duration.
  2. Create an async main function:
#[tokio:: main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    RustApi::auto()
        .layer(CorsLayer::permissive()) // Error here
        .layer(RateLimitLayer::new(100, Duration::from_secs(60)))
        .run("127.0.0.1:3000").await
}
  1. Compilation fails with error:
error[E0277]:  the trait bound `rustapi_rs::CorsLayer: MiddlewareLayer` is not satisfied

Expected Behavior

CorsLayer should work like other middleware layers (RateLimitLayer, tracingLayer, RequestIdLayer, etc) and be useable with the layer() method.

Actual Behavior

Compilation fails with trait bound error. CorsLayer does not implement MiddlewareLayer trait, so it cannot be used with layer().

Additional Context

Environment:

  • rustapi-rs: version 0.1.7
  • Rust version: 1.75.0
  • OS: Windows/Linux/macOS
  • Cargo.toml:
rustapi-rs = { version = "0.1.7", features = ["cors"] }

Root Cause:
CorsLayer in mod.rs is missing the impl MiddlewareLayer for CorsLayer block that other layers have.

Suggested Fix:
Add MiddlewareLayer implementation to CorsLayer, similar to how RateLimitLayer implements it in mod.rs.

Checklist

  • I have searched for similar issues and couldn't find any.
  • I have tried the latest version of RustAPI.
  • I have provided all the required information above.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions