我在 rocket_cors 方法上遇到 Cargo 运行 错误
I have a Cargo run error, on rocket_cors method
我正在尝试让我的 Rust Rocket 应用程序通过 cargo 运行
use rocket::http::Method;
fn make_cors() -> Cors {
let allowed_origins = AllowedOrigins::some_exact(&[ // 4.
"http://localhost:3000",
"http://127.0.0.1:3000",
"http://localhost:8000",
"http://0.0.0.0:8000",
]);
CorsOptions { // 5.
allowed_origins,
allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), // 1.
allowed_headers: AllowedHeaders::some(&[
"Authorization",
"Accept",
"Access-Control-Allow-Origin", // 6.
]),
allow_credentials: true,
..Default::default()
}.to_cors().expect("error while building CORS")
}
以下错误困扰着我:
the trait bound `rocket_cors::Method: std::convert::From<rocket::http::Method>` is not satisfied
the trait `std::convert::From<rocket::http::Method>` is not implemented for `rocket_cors::Method`
编辑:
固定为 rocket_cors::Method
现在出现以下错误:
no associated item named `Get` found for struct `rocket_cors::Method` in the current scope
--> src/main.rs:24:35
|
24 | allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), // 1.
| ^^^ associated item not found in `rocket_cors::Method`
你应该使用 Method
wrapped by the rocket_cors
,而不是 rocket
本身的那个,因为根据 rocket_cors
所说
A wrapper type around rocket::http::Method
to support serialization and deserialization.
所以他们不一样。
我正在尝试让我的 Rust Rocket 应用程序通过 cargo 运行
use rocket::http::Method;
fn make_cors() -> Cors {
let allowed_origins = AllowedOrigins::some_exact(&[ // 4.
"http://localhost:3000",
"http://127.0.0.1:3000",
"http://localhost:8000",
"http://0.0.0.0:8000",
]);
CorsOptions { // 5.
allowed_origins,
allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), // 1.
allowed_headers: AllowedHeaders::some(&[
"Authorization",
"Accept",
"Access-Control-Allow-Origin", // 6.
]),
allow_credentials: true,
..Default::default()
}.to_cors().expect("error while building CORS")
}
以下错误困扰着我:
the trait bound `rocket_cors::Method: std::convert::From<rocket::http::Method>` is not satisfied
the trait `std::convert::From<rocket::http::Method>` is not implemented for `rocket_cors::Method`
编辑:
固定为 rocket_cors::Method
现在出现以下错误:
no associated item named `Get` found for struct `rocket_cors::Method` in the current scope
--> src/main.rs:24:35
|
24 | allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), // 1.
| ^^^ associated item not found in `rocket_cors::Method`
你应该使用 Method
wrapped by the rocket_cors
,而不是 rocket
本身的那个,因为根据 rocket_cors
所说
A wrapper type around
rocket::http::Method
to support serialization and deserialization.
所以他们不一样。