I'm trying to handle cors requests in my rocket application, I have followed the rocket_cors guard example by creating and manageing a cors struct, then mounting rocket_cors::catch_all_options_routes(). This causes a trait bound error.
main.rs
...
#[rocket::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cors = rocket_cors::CorsOptions::default().to_cors()?;
let _ = rocket::build()
.mount("/", routes![sample, sample_index])
.mount("/", rocket_cors::catch_all_options_routes())
.attach(Shield::new())
.attach(Db::init())
.manage(cors)
.launch().await?;
Ok(())
}
Cargo.toml
[dependencies.rocket]
version = "0.5.0-rc.2"
features = ["json"]
[dependencies]
rocket_cors = "0.5.2"
Error
error[E0277]: the trait bound `Vec<Route>: From<Vec<rocket::router::route::Route>>` is not satisfied
--> src/main.rs:313:21
|
313 | .mount("/", rocket_cors::catch_all_options_routes())
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<Vec<rocket::router::route::Route>>` is not implemented for `Vec<Route>`
| |
| required by a bound introduced by this call
|
= help: the trait `From<FileServer>` is implemented for `Vec<Route>`
= note: required for `Vec<rocket::router::route::Route>` to implement `Into<Vec<Route>>`
note: required by a bound in `Rocket::<Build>::mount`
--> /home/aiden/.cargo/registry/src/github.com-1ecc6299db9ec823/rocket-0.5.0-rc.2/src/rocket.rs:341:18
|
341 | R: Into<Vec<Route>>
| ^^^^^^^^^^^^^^^^ required by this bound in `Rocket::<Build>::mount`
For more information about this error, try `rustc --explain E0277`.