FAQ Example is Incorrect
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.
System Checks
- [x] I confirmed that the issue still exists on
masteron GitHub. - [x] I was unable to find a previous report of this problem.
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)
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.
I think we can file this under #1274.