I ended up not being able to work it out. I took a compromise where strings could be passed through extensions normally, I converted the enum type to a string, and then converted the string to an enum in mapper_response
#[derive(Debug, Deserialize, Clone, AsRefStr, EnumString)]
#[serde(tag = "type", content = "data")]
pub enum Error {
LoginFail,
// Auth error
AuthFaildNoAuthTokenCookie,
AuthFaildTokenFormatWrong,
AuthFaildCtxNotInRequestExt,
// model errors.
ListenerCreationFailed(ListenerCreationError),
ListenerRemoveFailed,
ListenerEditFailed,
}
mapper_response:
response.extensions_mut().insert(self.as_ref().to_string());