Skip to content

Commit

Permalink
Chore: A few clippy inspired changes
Browse files Browse the repository at this point in the history
* Combine identical `match` branches into one statement with a `|` symbol
* Use `_` in a 9-bit binary values (I didn't even realize they were 9-bit instead of the common 8-bit until I did this)
  • Loading branch information
nyurik committed Sep 19, 2023
1 parent a9822ec commit 2d4716a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion axum-core/src/ext_traits/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl RequestExt for Request {
*req.uri_mut() = self.uri().clone();
*req.headers_mut() = std::mem::take(self.headers_mut());
*req.extensions_mut() = std::mem::take(self.extensions_mut());
let (mut parts, _) = req.into_parts();
let (mut parts, ()) = req.into_parts();

Box::pin(async move {
let result = E::from_request_parts(&mut parts, state).await;
Expand Down
6 changes: 2 additions & 4 deletions axum-macros/src/from_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ impl State {
/// ```
fn trait_generics(&self) -> impl Iterator<Item = Type> {
match self {
State::Default(inner) => iter::once(inner.clone()),
State::Custom(inner) => iter::once(inner.clone()),
State::Default(inner) | State::Custom(inner) => iter::once(inner.clone()),
State::CannotInfer => iter::once(parse_quote!(S)),
}
}
Expand All @@ -85,8 +84,7 @@ impl State {
impl ToTokens for State {
fn to_tokens(&self, tokens: &mut TokenStream) {
match self {
State::Custom(inner) => inner.to_tokens(tokens),
State::Default(inner) => inner.to_tokens(tokens),
State::Custom(inner) | State::Default(inner) => inner.to_tokens(tokens),
State::CannotInfer => quote! { S }.to_tokens(tokens),
}
}
Expand Down
16 changes: 8 additions & 8 deletions axum/src/routing/method_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ pub struct MethodFilter(u16);

impl MethodFilter {
/// Match `DELETE` requests.
pub const DELETE: Self = Self::from_bits(0b000000010);
pub const DELETE: Self = Self::from_bits(0b0_0000_0010);
/// Match `GET` requests.
pub const GET: Self = Self::from_bits(0b000000100);
pub const GET: Self = Self::from_bits(0b0_0000_0100);
/// Match `HEAD` requests.
pub const HEAD: Self = Self::from_bits(0b000001000);
pub const HEAD: Self = Self::from_bits(0b0_0000_1000);
/// Match `OPTIONS` requests.
pub const OPTIONS: Self = Self::from_bits(0b000010000);
pub const OPTIONS: Self = Self::from_bits(0b0_0001_0000);
/// Match `PATCH` requests.
pub const PATCH: Self = Self::from_bits(0b000100000);
pub const PATCH: Self = Self::from_bits(0b0_0010_0000);
/// Match `POST` requests.
pub const POST: Self = Self::from_bits(0b001000000);
pub const POST: Self = Self::from_bits(0b0_0100_0000);
/// Match `PUT` requests.
pub const PUT: Self = Self::from_bits(0b010000000);
pub const PUT: Self = Self::from_bits(0b0_1000_0000);
/// Match `TRACE` requests.
pub const TRACE: Self = Self::from_bits(0b100000000);
pub const TRACE: Self = Self::from_bits(0b1_0000_0000);

const fn bits(&self) -> u16 {
let bits = self;
Expand Down

0 comments on commit 2d4716a

Please sign in to comment.