mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-29 00:00:18 +02:00
style: use Self to avoid unnecessary repetition (#3396)
This commit is contained in:
@@ -97,8 +97,8 @@ pub(crate) enum FunctionKind {
|
||||
impl fmt::Display for FunctionKind {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
FunctionKind::Handler => f.write_str("handler"),
|
||||
FunctionKind::Middleware => f.write_str("middleware"),
|
||||
Self::Handler => f.write_str("handler"),
|
||||
Self::Middleware => f.write_str("middleware"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,8 +106,8 @@ impl fmt::Display for FunctionKind {
|
||||
impl FunctionKind {
|
||||
fn name_uppercase_plural(&self) -> &'static str {
|
||||
match self {
|
||||
FunctionKind::Handler => "Handlers",
|
||||
FunctionKind::Middleware => "Middleware",
|
||||
Self::Handler => "Handlers",
|
||||
Self::Middleware => "Middleware",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ pub(crate) enum Trait {
|
||||
impl Trait {
|
||||
fn via_marker_type(&self) -> Option<Type> {
|
||||
match self {
|
||||
Trait::FromRequest => Some(parse_quote!(M)),
|
||||
Trait::FromRequestParts => None,
|
||||
Self::FromRequest => Some(parse_quote!(M)),
|
||||
Self::FromRequestParts => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,8 @@ impl Trait {
|
||||
impl fmt::Display for Trait {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Trait::FromRequest => f.write_str("FromRequest"),
|
||||
Trait::FromRequestParts => f.write_str("FromRequestParts"),
|
||||
Self::FromRequest => f.write_str("FromRequest"),
|
||||
Self::FromRequestParts => f.write_str("FromRequestParts"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,9 +50,9 @@ impl State {
|
||||
/// ```
|
||||
fn impl_generics(&self) -> impl Iterator<Item = Type> {
|
||||
match self {
|
||||
State::Default(inner) => Some(inner.clone()),
|
||||
State::Custom(_) => None,
|
||||
State::CannotInfer => Some(parse_quote!(S)),
|
||||
Self::Default(inner) => Some(inner.clone()),
|
||||
Self::Custom(_) => None,
|
||||
Self::CannotInfer => Some(parse_quote!(S)),
|
||||
}
|
||||
.into_iter()
|
||||
}
|
||||
@@ -63,18 +63,18 @@ impl State {
|
||||
/// ```
|
||||
fn trait_generics(&self) -> impl Iterator<Item = Type> {
|
||||
match self {
|
||||
State::Default(inner) | State::Custom(inner) => iter::once(inner.clone()),
|
||||
State::CannotInfer => iter::once(parse_quote!(S)),
|
||||
Self::Default(inner) | Self::Custom(inner) => iter::once(inner.clone()),
|
||||
Self::CannotInfer => iter::once(parse_quote!(S)),
|
||||
}
|
||||
}
|
||||
|
||||
fn bounds(&self) -> TokenStream {
|
||||
match self {
|
||||
State::Custom(_) => quote! {},
|
||||
State::Default(inner) => quote! {
|
||||
Self::Custom(_) => quote! {},
|
||||
Self::Default(inner) => quote! {
|
||||
#inner: ::std::marker::Send + ::std::marker::Sync,
|
||||
},
|
||||
State::CannotInfer => quote! {
|
||||
Self::CannotInfer => quote! {
|
||||
S: ::std::marker::Send + ::std::marker::Sync,
|
||||
},
|
||||
}
|
||||
@@ -84,8 +84,8 @@ impl State {
|
||||
impl ToTokens for State {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
match self {
|
||||
State::Custom(inner) | State::Default(inner) => inner.to_tokens(tokens),
|
||||
State::CannotInfer => quote! { S }.to_tokens(tokens),
|
||||
Self::Custom(inner) | Self::Default(inner) => inner.to_tokens(tokens),
|
||||
Self::CannotInfer => quote! { S }.to_tokens(tokens),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ impl<I> WithPosition<I>
|
||||
where
|
||||
I: Iterator,
|
||||
{
|
||||
pub(crate) fn new(iter: impl IntoIterator<IntoIter = I>) -> WithPosition<I> {
|
||||
WithPosition {
|
||||
pub(crate) fn new(iter: impl IntoIterator<IntoIter = I>) -> Self {
|
||||
Self {
|
||||
handled_first: false,
|
||||
peekable: iter.into_iter().fuse().peekable(),
|
||||
}
|
||||
@@ -72,7 +72,7 @@ pub(crate) enum Position<T> {
|
||||
impl<T> Position<T> {
|
||||
pub(crate) fn into_inner(self) -> T {
|
||||
match self {
|
||||
Position::First(x) | Position::Middle(x) | Position::Last(x) | Position::Only(x) => x,
|
||||
Self::First(x) | Self::Middle(x) | Self::Last(x) | Self::Only(x) => x,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user