mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-02 00:00:22 +02:00
style: use Self to avoid unnecessary repetition (#3396)
This commit is contained in:
@@ -321,13 +321,13 @@ mod tests {
|
||||
}
|
||||
|
||||
impl FromRef<AppState> for Key {
|
||||
fn from_ref(state: &AppState) -> Key {
|
||||
fn from_ref(state: &AppState) -> Self {
|
||||
state.key.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRef<AppState> for CustomKey {
|
||||
fn from_ref(state: &AppState) -> CustomKey {
|
||||
fn from_ref(state: &AppState) -> Self {
|
||||
state.custom_key.clone()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ where
|
||||
key,
|
||||
_marker: _,
|
||||
} = PrivateCookieJar::from_headers(&parts.headers, key);
|
||||
Ok(PrivateCookieJar {
|
||||
Ok(Self {
|
||||
jar,
|
||||
key,
|
||||
_marker: PhantomData,
|
||||
|
||||
@@ -153,7 +153,7 @@ where
|
||||
key,
|
||||
_marker: _,
|
||||
} = SignedCookieJar::from_headers(&parts.headers, key);
|
||||
Ok(SignedCookieJar {
|
||||
Ok(Self {
|
||||
jar,
|
||||
key,
|
||||
_marker: PhantomData,
|
||||
|
||||
@@ -36,7 +36,7 @@ where
|
||||
|
||||
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
|
||||
parts
|
||||
.extract::<Option<Host>>()
|
||||
.extract::<Option<Self>>()
|
||||
.await
|
||||
.ok()
|
||||
.flatten()
|
||||
@@ -55,7 +55,7 @@ where
|
||||
_state: &S,
|
||||
) -> Result<Option<Self>, Self::Rejection> {
|
||||
if let Some(host) = parse_forwarded(&parts.headers) {
|
||||
return Ok(Some(Host(host.to_owned())));
|
||||
return Ok(Some(Self(host.to_owned())));
|
||||
}
|
||||
|
||||
if let Some(host) = parts
|
||||
@@ -63,7 +63,7 @@ where
|
||||
.get(X_FORWARDED_HOST_HEADER_KEY)
|
||||
.and_then(|host| host.to_str().ok())
|
||||
{
|
||||
return Ok(Some(Host(host.to_owned())));
|
||||
return Ok(Some(Self(host.to_owned())));
|
||||
}
|
||||
|
||||
if let Some(host) = parts
|
||||
@@ -71,11 +71,11 @@ where
|
||||
.get(http::header::HOST)
|
||||
.and_then(|host| host.to_str().ok())
|
||||
{
|
||||
return Ok(Some(Host(host.to_owned())));
|
||||
return Ok(Some(Self(host.to_owned())));
|
||||
}
|
||||
|
||||
if let Some(authority) = parts.uri.authority() {
|
||||
return Ok(Some(Host(parse_authority(authority).to_owned())));
|
||||
return Ok(Some(Self(parse_authority(authority).to_owned())));
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
|
||||
@@ -91,7 +91,7 @@ where
|
||||
serde_html_form::Deserializer::new(form_urlencoded::parse(query.as_bytes()));
|
||||
let value = serde_path_to_error::deserialize(deserializer)
|
||||
.map_err(FailedToDeserializeQueryString::from_err)?;
|
||||
Ok(Query(value))
|
||||
Ok(Self(value))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,9 +170,9 @@ where
|
||||
serde_html_form::Deserializer::new(form_urlencoded::parse(query.as_bytes()));
|
||||
let value = serde_path_to_error::deserialize(deserializer)
|
||||
.map_err(FailedToDeserializeQueryString::from_err)?;
|
||||
Ok(OptionalQuery(Some(value)))
|
||||
Ok(Self(Some(value)))
|
||||
} else {
|
||||
Ok(OptionalQuery(None))
|
||||
Ok(Self(None))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ where
|
||||
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
|
||||
// Within Forwarded header
|
||||
if let Some(scheme) = parse_forwarded(&parts.headers) {
|
||||
return Ok(Scheme(scheme.to_owned()));
|
||||
return Ok(Self(scheme.to_owned()));
|
||||
}
|
||||
|
||||
// X-Forwarded-Proto
|
||||
@@ -47,12 +47,12 @@ where
|
||||
.get(X_FORWARDED_PROTO_HEADER_KEY)
|
||||
.and_then(|scheme| scheme.to_str().ok())
|
||||
{
|
||||
return Ok(Scheme(scheme.to_owned()));
|
||||
return Ok(Self(scheme.to_owned()));
|
||||
}
|
||||
|
||||
// From parts of an HTTP/2 request
|
||||
if let Some(scheme) = parts.uri.scheme_str() {
|
||||
return Ok(Scheme(scheme.to_owned()));
|
||||
return Ok(Self(scheme.to_owned()));
|
||||
}
|
||||
|
||||
Err(SchemeMissing)
|
||||
|
||||
@@ -119,7 +119,7 @@ where
|
||||
|
||||
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> {
|
||||
let extractor = E::from_request(req, state).await?;
|
||||
Ok(WithRejection(extractor, PhantomData))
|
||||
Ok(Self(extractor, PhantomData))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ where
|
||||
|
||||
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
|
||||
let extractor = E::from_request_parts(parts, state).await?;
|
||||
Ok(WithRejection(extractor, PhantomData))
|
||||
Ok(Self(extractor, PhantomData))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ mod tests {
|
||||
|
||||
impl From<()> for TestRejection {
|
||||
fn from(_: ()) -> Self {
|
||||
TestRejection
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user