Closed gavadinov closed 3 years ago
This will make it easier to wrap the parse error in another error. Right now to achieve this you have to do something like
pub enum Error { AnotherError, ParseError(httparse::Error), } impl Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { let message = match self { AnotherError => String::from("MESSAGE"), Error::ParseError(e) => format!("{}", e), ...
By going through the Display trait we have to allocate a new String and copy the static error message into it. If we had access to the &'static str error description the match above would be much simpler and will have no need for allocations.
&'static str
AnotherError => "MESSAGE", Error::ParseError(e) => e.description_str(),
This will make it easier to wrap the parse error in another error. Right now to achieve this you have to do something like
By going through the Display trait we have to allocate a new String and copy the static error message into it. If we had access to the
&'static str
error description the match above would be much simpler and will have no need for allocations.