我在试着让我的铁锈火箭应用程序在货运过程中运行
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`发布于 2022-05-29 07:56:25
您应该使用Method wrapped by the rocket_cors,而不是来自rocket本身的,因为根据rocket_cors的说法
:围绕
rocket::http::Method支持序列化和反序列化的包装器类型。
所以他们不一样了。
https://stackoverflow.com/questions/72421820
复制相似问题