mirror of https://github.com/http-rs/http-types
Compare commits
6 Commits
6f38b3ea86
...
2af0a7a6f4
Author | SHA1 | Date |
---|---|---|
Jeremiah Senkpiel | 2af0a7a6f4 | |
Jeremiah Senkpiel | 7236637ec1 | |
Yoshua Wuyts | 72f421d3cb | |
Alexander Lyon | 18278ffc2b | |
Alexander Lyon | 5f8040d35a | |
Alexander Lyon | e8b7532775 |
14
src/body.rs
14
src/body.rs
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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(),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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`.
|
||||
|
|
|
@ -391,7 +391,7 @@ impl Serialize for Method {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.to_string())
|
||||
serializer.serialize_str(self.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -24,7 +24,7 @@ impl Serialize for Version {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.to_string())
|
||||
serializer.serialize_str(self.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue