Skip to content

Instantly share code, notes, and snippets.

@AnyTimeTraveler
Last active Jun 27, 2021
Embed
What would you like to do?
response_result.rs
Compiling kitzretter_backend v0.1.0 (/home/simon/projects/kitzretter_backend)
error[E0392]: parameter `'a` is never used
--> src/kitzretter/www/error/response_result.rs:9:25
|
9 | pub enum ResponseResult<'a, T> where T: Responder<'a, 'a> {
| ^^ unused parameter
|
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`
error[E0277]: the trait bound `T: Responder<'a, 'a>` is not satisfied
--> src/kitzretter/www/error/response_result.rs:15:35
|
9 | pub enum ResponseResult<'a, T> where T: Responder<'a, 'a> {
| ----------------- required by this bound in `ResponseResult`
...
15 | impl<'a, T> Responder<'a, 'a> for ResponseResult<'a, T> {
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Responder<'a, 'a>` is not implemented for `T`
|
help: consider restricting type parameter `T`
|
15 | impl<'a, T: askama_rocket::Responder<'a, 'a>> Responder<'a, 'a> for ResponseResult<'a, T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `T: Responder<'a, 'a>` is not satisfied
--> src/kitzretter/www/error/response_result.rs:25:58
|
9 | pub enum ResponseResult<'a, T> where T: Responder<'a, 'a> {
| ----------------- required by this bound in `ResponseResult`
...
25 | impl<'a, T> FromResidual<Result<Infallible, String>> for ResponseResult<'a, T> {
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Responder<'a, 'a>` is not implemented for `T`
|
help: consider restricting type parameter `T`
|
25 | impl<'a, T: askama_rocket::Responder<'a, 'a>> FromResidual<Result<Infallible, String>> for ResponseResult<'a, T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `T: Responder<'a, 'a>` is not satisfied
--> src/kitzretter/www/error/response_result.rs:34:21
|
9 | pub enum ResponseResult<'a, T> where T: Responder<'a, 'a> {
| ----------------- required by this bound in `ResponseResult`
...
34 | impl<'a, T> Try for ResponseResult<'a, T> {
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Responder<'a, 'a>` is not implemented for `T`
|
help: consider restricting type parameter `T`
|
34 | impl<'a, T: askama_rocket::Responder<'a, 'a>> Try for ResponseResult<'a, T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `T: Responder<'a, 'a>` is not satisfied
--> src/kitzretter/www/error/response_result.rs:16:19
|
9 | pub enum ResponseResult<'a, T> where T: Responder<'a, 'a> {
| ----------------- required by this bound in `ResponseResult`
...
16 | fn respond_to(self, request: &'a Request<'_>) -> response::Result<'a> {
| ^^^^ the trait `Responder<'a, 'a>` is not implemented for `T`
|
help: consider restricting type parameter `T`
|
15 | impl<'a, T: askama_rocket::Responder<'a, 'a>> Responder<'a, 'a> for ResponseResult<'a, T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `T: Responder<'a, 'a>` is not satisfied
--> src/kitzretter/www/error/response_result.rs:26:63
|
9 | pub enum ResponseResult<'a, T> where T: Responder<'a, 'a> {
| ----------------- required by this bound in `ResponseResult`
...
26 | fn from_residual(residual: Result<Infallible, String>) -> Self {
| ^^^^ the trait `Responder<'a, 'a>` is not implemented for `T`
|
help: consider restricting type parameter `T`
|
25 | impl<'a, T: askama_rocket::Responder<'a, 'a>> FromResidual<Result<Infallible, String>> for ResponseResult<'a, T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `T: Responder<'a, 'a>` is not satisfied
--> src/kitzretter/www/error/response_result.rs:38:45
|
9 | pub enum ResponseResult<'a, T> where T: Responder<'a, 'a> {
| ----------------- required by this bound in `ResponseResult`
...
38 | fn from_output(output: Self::Output) -> Self {
| ^^^^ the trait `Responder<'a, 'a>` is not implemented for `T`
|
help: consider restricting type parameter `T`
|
34 | impl<'a, T: askama_rocket::Responder<'a, 'a>> Try for ResponseResult<'a, T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `T: Responder<'a, 'a>` is not satisfied
--> src/kitzretter/www/error/response_result.rs:42:15
|
9 | pub enum ResponseResult<'a, T> where T: Responder<'a, 'a> {
| ----------------- required by this bound in `ResponseResult`
...
42 | fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
| ^^^^ the trait `Responder<'a, 'a>` is not implemented for `T`
|
help: consider restricting type parameter `T`
|
34 | impl<'a, T: askama_rocket::Responder<'a, 'a>> Try for ResponseResult<'a, T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 8 previous errors
Some errors have detailed explanations: E0277, E0392.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `kitzretter_backend`
To learn more, run the command again with --verbose.
use std::convert::Infallible;
use std::ops::{ControlFlow::{self, Break, Continue}, FromResidual, Try};
use askama_rocket::respond;
use rocket::{Request, response::{self, Responder}};
use super::ErrorTemplate;
pub enum ResponseResult<'a, T> where T: Responder<'a, 'a> {
Okay(T),
Error(String),
}
impl<'a, T> Responder<'a, 'a> for ResponseResult<'a, T> {
fn respond_to(self, request: &'a Request<'_>) -> response::Result<'a> {
match self {
ResponseResult::Okay(r) => { r.respond_to(request) }
ResponseResult::Error(message) => { respond(&ErrorTemplate { message }, "html") }
}
}
}
impl<'a, T> FromResidual<Result<Infallible, String>> for ResponseResult<'a, T> {
fn from_residual(residual: Result<Infallible, String>) -> Self {
match residual {
Ok(_) => unreachable!(),
Err(e) => ResponseResult::Error(e)
}
}
}
impl<'a, T> Try for ResponseResult<'a, T> {
type Output = T;
type Residual = Result<Infallible, String>;
fn from_output(output: Self::Output) -> Self {
ResponseResult::Okay(output)
}
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
match self {
ResponseResult::Okay(t) => Continue(t),
ResponseResult::Error(e) => Break(Err(e))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment