Rocket icon indicating copy to clipboard operation
Rocket copied to clipboard

FAQ Example is Incorrect

Open BnDLett opened this issue 6 months ago • 1 comments

What kind of documentation problem are you reporting?

Technical Problem

Where is the issue found?

https://rocket.rs/guide/v0.5/faq/#response-headers

What's wrong?

FAQ example does not work.

Image

System Checks

  • [x] I confirmed that the issue still exists on master on GitHub.
  • [x] I was unable to find a previous report of this problem.

BnDLett avatar Jun 14 '25 09:06 BnDLett

The compiler is using the implementation of From<T> for T here. You can define your own to construct a MyResponder:

impl<T> From<T> for MyResponder<T> {
    fn from(value: T) -> Self {
        Self {
            inner: value,
            header: todo!("insert your default header value"),
        }
    }
}

I agree the documentation should be a little more complete or at least warn that the code does not compile as is (HeaderType is not a real type)

DavidSkrundz avatar Jun 14 '25 17:06 DavidSkrundz

I have mixed opinions here. First, if you check the docs source (docs/14-faq.md), you can see the hidden code needed to make it compile. In the example, HeaderType is used as an alias for Header<'static>, and the from implementation looks much like yours. However, we don't want to show specific code more than needed. In this case, although you can use Header<'static> in the responder struct to add arbitrary headers, it's better to attach specific header types (e.g. ContentType).

That being said, we don't actually provide many of these, so maybe it doesn't matter right now.

the10thWiz avatar Jun 19 '25 22:06 the10thWiz

I think we can file this under #1274.

SergioBenitez avatar Jun 20 '25 21:06 SergioBenitez