Problem with lifetimes while upgrading to rocket 0.5.0-rc.1

I am currently in the process of updating from rocket 0.4.5 to the new 0.5 release candidate.

I used to have three result types:

  1. RedirectResult
  2. TemplateResult
  3. ResponseResult

They all either Respond with the thing in their name on success or with an ErrorTemplate that shows the given string in the Error-variant.

In the new version, generating a Response has changed, so I thought of creating a type that can handle all of the above.
I found that all of them implement the Responder trait, but I can't seem to figure out how to fix the lifetime errors I'm getting.
If I remove the lifetime in the enum, it complains about the lack of them, if I don't it complains about it being unused...

I have only been programming Rust for about a year on my own time. I don't know how to use lifetimes properly, yet. I usually just do what the compiler suggests and it works.

Code and compiler output

I can't think of anything else I can google, so I'm posting here.

Thank you in advance for taking your time

Try this.

pub enum ResponseResult<T> {

impl<'r, 'o: 'r, T> Responder<'r, 'o> for ResponseResult<T>
    T: Responder<'r, 'o>,
    fn respond_to(self, request: &'r Request<'_>) -> response::Result<'o> {
        match self {
            ResponseResult::Okay(r) => { r.respond_to(request) }
            ResponseResult::Error(message) => { respond(&ErrorTemplate { message }, "html") }

Oh, I see!

ResponseResult is capable of holding any type T, but it only implements Responder for T that are Responder themselves!

Thank you for the help, that worked! :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.