Hello, sorry the title don't say much!
I have this extractor:
pub async fn extract(req: &mut Request) -> Result<HashSet<Role>, Response> {
let Some(auth) = req.headers().get("authorization") else {
req.extensions_mut().insert(UserMeta::new(-1, vec![]));
return Ok(HashSet::from([Role::Guest]));
};
let Some((scheme, token)) = auth
.to_str()
.ok()
.and_then(|value| value.trim().split_once(' '))
else {
warn!("Malformed or invalid authorization header");
return Err(ServiceError::Unauthorized.into_response());
};
if !scheme.eq_ignore_ascii_case("bearer") {
warn!("Unsupported authorization scheme: {scheme}");
return Err(ServiceError::Unauthorized.into_response());
}
match auth::decode_jwt(token).await {
Ok(claims) => {
let mut authorities = HashSet::with_capacity(1);
authorities.insert(claims.role.clone());
req.extensions_mut()
.insert(UserMeta::new(claims.id, claims.channels));
Ok(authorities)
}
Err(e) => {
error!("JWT decode error: {e:?}");
Err(ServiceError::Unauthorized.into_response())
}
}
}
In current stable compiler that works fine, but when I switch to nightly clippy is a bit more strict and prints this error:
the `Err`-variant returned from this function is very large
try reducing the size of `axum::http::Response<axum::body::Body>`, for example by boxing large elements or replacing it with `Box<axum::http::Response<axum::body::Body>>`
for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
`-D clippy::result-large-err` implied by `-D clippy::perf`
to override `-D clippy::perf` add `#[allow(clippy::result_large_err)]`
Supposedly this is not a big issue and I could ignore it with #[allow(clippy::result_large_err)]. But I wonder if there is a better solution?
Hello, sorry the title don't say much!
I have this extractor:
In current stable compiler that works fine, but when I switch to nightly clippy is a bit more strict and prints this error:
Supposedly this is not a big issue and I could ignore it with
#[allow(clippy::result_large_err)]. But I wonder if there is a better solution?