Compare commits

...

6 Commits

Author SHA1 Message Date
Jeremiah Senkpiel 2af0a7a6f4 lints: fix clippy lints 2022-05-09 18:07:24 -07:00
Jeremiah Senkpiel 7236637ec1
Merge pull request #399 from arlyon/v2.x.x-backports
Fix all failing clippy lints for backports branch
2022-05-09 17:59:04 -07:00
Yoshua Wuyts 72f421d3cb
Backport fix from main instead 2022-03-29 11:05:11 +01:00
Alexander Lyon 18278ffc2b
Round to microsecond accuracy rather than divide for second accuracy 2022-03-29 11:02:28 +01:00
Alexander Lyon 5f8040d35a
Fix bug where cache directives are not properly made lowercase 2022-03-29 10:47:51 +01:00
Alexander Lyon e8b7532775
Fix all failing clippy lints for CI 2022-03-29 10:42:47 +01:00
10 changed files with 20 additions and 20 deletions

View File

@ -277,7 +277,7 @@ impl Body {
pub async fn into_json<T: DeserializeOwned>(mut self) -> crate::Result<T> {
let mut buf = Vec::with_capacity(1024);
self.read_to_end(&mut buf).await?;
Ok(serde_json::from_slice(&buf).status(StatusCode::UnprocessableEntity)?)
serde_json::from_slice(&buf).status(StatusCode::UnprocessableEntity)
}
/// Creates a `Body` from a type, serializing it using form encoding.
@ -346,7 +346,7 @@ impl Body {
/// ```
pub async fn into_form<T: DeserializeOwned>(self) -> crate::Result<T> {
let s = self.into_string().await?;
Ok(serde_urlencoded::from_str(&s).status(StatusCode::UnprocessableEntity)?)
serde_urlencoded::from_str(&s).status(StatusCode::UnprocessableEntity)
}
/// Create a `Body` from a file.
@ -507,7 +507,7 @@ impl AsyncRead for Body {
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
let mut buf = match self.length {
let buf = match self.length {
None => buf,
Some(length) if length == self.bytes_read => return Poll::Ready(Ok(0)),
Some(length) => {
@ -516,7 +516,7 @@ impl AsyncRead for Body {
}
};
let bytes = ready!(Pin::new(&mut self.reader).poll_read(cx, &mut buf))?;
let bytes = ready!(Pin::new(&mut self.reader).poll_read(cx, buf))?;
self.bytes_read += bytes;
Poll::Ready(Ok(bytes))
}
@ -551,7 +551,7 @@ async fn peek_mime(file: &mut async_std::fs::File) -> io::Result<Option<Mime>> {
/// This is useful for plain-text formats such as HTML and CSS.
#[cfg(all(feature = "fs", not(target_os = "unknown")))]
fn guess_ext(path: &std::path::Path) -> Option<Mime> {
let ext = path.extension().map(|p| p.to_str()).flatten();
let ext = path.extension().and_then(|p| p.to_str());
ext.and_then(Mime::from_extension)
}
@ -565,7 +565,7 @@ mod test {
async fn json_status() {
#[derive(Debug, Deserialize)]
struct Foo {
inner: String,
_inner: String,
}
let body = Body::empty();
let res = body.into_json::<Foo>().await;
@ -576,7 +576,7 @@ mod test {
async fn form_status() {
#[derive(Debug, Deserialize)]
struct Foo {
inner: String,
_inner: String,
}
let body = Body::empty();
let res = body.into_form::<Foo>().await;

View File

@ -88,7 +88,7 @@ impl CacheDirective {
return Ok(None);
}
s.to_lowercase();
let s = s.to_lowercase();
let mut parts = s.split('=');
let next = parts.next().unwrap();

View File

@ -96,8 +96,8 @@ impl ClearSiteData {
let mut output = String::new();
for (n, etag) in self.entries.iter().enumerate() {
match n {
0 => write!(output, "{}", etag.to_string()).unwrap(),
_ => write!(output, ", {}", etag.to_string()).unwrap(),
0 => write!(output, "{}", etag).unwrap(),
_ => write!(output, ", {}", etag).unwrap(),
};
}

View File

@ -88,8 +88,8 @@ impl IfMatch {
let mut output = String::new();
for (n, etag) in self.entries.iter().enumerate() {
match n {
0 => write!(output, "{}", etag.to_string()).unwrap(),
_ => write!(output, ", {}", etag.to_string()).unwrap(),
0 => write!(output, "{}", etag).unwrap(),
_ => write!(output, ", {}", etag).unwrap(),
};
}

View File

@ -94,8 +94,8 @@ impl IfNoneMatch {
let mut output = String::new();
for (n, etag) in self.entries.iter().enumerate() {
match n {
0 => write!(output, "{}", etag.to_string()).unwrap(),
_ => write!(output, ", {}", etag.to_string()).unwrap(),
0 => write!(output, "{}", etag).unwrap(),
_ => write!(output, ", {}", etag).unwrap(),
};
}

View File

@ -159,7 +159,7 @@ impl Error {
/// Retrieves a reference to the type name of the error, if available.
pub fn type_name(&self) -> Option<&str> {
self.type_name.as_deref()
self.type_name
}
/// Converts anything which implements `Display` into an `http_types::Error`.

View File

@ -391,7 +391,7 @@ impl Serialize for Method {
where
S: Serializer,
{
serializer.serialize_str(&self.to_string())
serializer.serialize_str(self.as_ref())
}
}

View File

@ -153,12 +153,12 @@ fn is_http_whitespace_char(c: char) -> bool {
/// [code point sequence collection](https://infra.spec.whatwg.org/#collect-a-sequence-of-code-points)
fn collect_code_point_sequence_char(input: &str, delimiter: char) -> (&str, &str) {
input.split_at(input.find(delimiter).unwrap_or_else(|| input.len()))
input.split_at(input.find(delimiter).unwrap_or(input.len()))
}
/// [code point sequence collection](https://infra.spec.whatwg.org/#collect-a-sequence-of-code-points)
fn collect_code_point_sequence_slice<'a>(input: &'a str, delimiter: &[char]) -> (&'a str, &'a str) {
input.split_at(input.find(delimiter).unwrap_or_else(|| input.len()))
input.split_at(input.find(delimiter).unwrap_or(input.len()))
}
/// [HTTP quoted string collection](https://fetch.spec.whatwg.org/#collect-an-http-quoted-string)

View File

@ -65,7 +65,7 @@ fn parse_entry(s: &str) -> crate::Result<Metric> {
let millis: f64 = value.parse().map_err(|_| {
format_err!("Server timing duration params must be a valid double-precision floating-point number.")
})?;
dur = Some(Duration::from_secs_f64(millis / 1000.0));
dur = Some(Duration::from_secs_f64(millis) / 1000);
}
"desc" => {
// Ensure quotes line up, and strip them from the resulting output

View File

@ -24,7 +24,7 @@ impl Serialize for Version {
where
S: Serializer,
{
serializer.serialize_str(&self.to_string())
serializer.serialize_str(self.as_ref())
}
}