Use the tower-http crate's cors middleware to handle Cross-Origin Resource Sharing in Rust web applications. Add the dependency to your Cargo.toml and wrap your service with the CORS layer in main.rs.
use tower_http::cors::{Any, CorsLayer};
use tower::ServiceBuilder;
let cors = CorsLayer::new()
.allow_origin(Any)
.allow_methods(Any)
.allow_headers(Any);
let app = ServiceBuilder::new()
.layer(cors)
.service(your_service);