我正在研究rust
//并且无法弄清楚如何在 . 上实现actix
trait ,或者如何转换为.tera
ResponseError
tera::Error
tera::Error
actix_web::Error
使用以下代码片段:
match TEMPLATES.render("index.html", &ctx) {
Ok(s) => Ok(HttpResponse::Ok().body(s)),
Err(e) => Err(e),
}
我收到一个错误:
mismatched types
expected struct `actix_web::Error`, found struct `tera::Error`rustc(E0308)
main.rs(71, 23): expected struct `actix_web::Error`, found struct `tera::Error`
所以我尝试了以下方法:
match TEMPLATES.render("index.html", &ctx) {
Ok(s) => Ok(HttpResponse::Ok().body(s)),
Err(e) => Err(e.into()),
}
但在这种情况下,我得到:
the trait bound `tera::Error: actix_web::ResponseError` is not satisfied
the trait `actix_web::ResponseError` is not implemented for `tera::Error`
note: required because of the requirements on the impl of `std::convert::From<tera::Error>` for `actix_web::Error`
note: required because of the requirements on the impl of `std::convert::Into<actix_web::Error>` for `tera::Error`rustc(E0277)
main.rs(71, 25): the trait `actix_web::ResponseError` is not implemented for `tera::Error`
所以最后我试过了:
use actix_web::{get, post, web, error, Error, ResponseError,
HttpRequest, HttpResponse, HttpServer,
App, Responder};
use tera::{Tera, Context};
use tera;
impl ResponseError for tera::Error {}
但现在得到:
only traits defined in the current crate can be implemented for arbitrary types
impl doesn't use only types from inside the current crate
note: define and implement a trait or new type insteadrustc(E0117)
main.rs(12, 1): impl doesn't use only types from inside the current crate
main.rs(12, 24): `tera::Error` is not defined in the current crate
我有match
块的函数签名如下:
#[get("/")]
async fn tst() -> Result<HttpResponse, Error> {}
我究竟做错了什么?