Skip to content

Commit

Permalink
Apply some clippy::pedantic lints
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealLorenz committed Nov 28, 2023
1 parent 1c4167a commit a8ae302
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
6 changes: 3 additions & 3 deletions rq-cli/src/components/response_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl ResponsePanel {
}

pub fn set_response(&mut self, value: Response) {
self.state = State::Received(value)
self.state = State::Received(value);
}
}

Expand Down Expand Up @@ -126,13 +126,13 @@ impl ResponsePanel {
match self.body() {
Ok(body) => match body {
Payload::Text(t) => iter::once(format!("decoded with encoding '{}':", t.charset))
.chain(t.text.lines().map(|s| s.to_string()))
.chain(t.text.lines().map(str::to_string))
.collect(),
Payload::Bytes(b) if self.show_raw => iter::once("lossy utf-8 decode:".to_string())
.chain(
String::from_utf8_lossy(&b.bytes)
.lines()
.map(|s| s.to_string()),
.map(str::to_string),
)
.collect(),
Payload::Bytes(_) => vec!["raw bytes".into()],
Expand Down
2 changes: 1 addition & 1 deletion rq-core/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ static CLIENT: Lazy<Client> = Lazy::new(|| {
pub struct Response {
pub status: StatusCode,
pub version: String,
pub payload: Payload,
pub headers: HeaderMap,
pub payload: Payload,
}

impl Response {
Expand Down
7 changes: 2 additions & 5 deletions rq-core/src/request/decode.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use bytes::Bytes;
use encoding_rs::{Encoding, UTF_8};

pub async fn decode_with_encoding(
bytes: Bytes,
encoding_name: &str,
) -> (String, &'static Encoding) {
pub fn decode_with_encoding(bytes: &Bytes, encoding_name: &str) -> (String, &'static Encoding) {
let encoding = Encoding::for_label(encoding_name.as_bytes()).unwrap_or(UTF_8);

let (text, encoding, _) = encoding.decode(&bytes);
let (text, encoding, _) = encoding.decode(bytes);
(text.into_owned(), encoding)
}
7 changes: 3 additions & 4 deletions rq-core/src/request/mime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ impl Payload {
(mime::TEXT, _) | (_, mime::JSON) => {
let charset = mime
.get_param("charset")
.map(|charset| charset.to_string())
.unwrap_or("utf-8".into());
.map_or("utf-8".into(), |charset| charset.to_string());
let (text, encoding) =
decode_with_encoding(response.bytes().await.unwrap(), &charset).await;
decode_with_encoding(&response.bytes().await.unwrap(), &charset);
Payload::Text(TextPayload {
charset: encoding.name().to_owned(),
text,
Expand Down Expand Up @@ -81,5 +80,5 @@ fn parse_extension(name: Name) -> Option<String> {
mime::XML => Some("xml"),
_ => None,
}
.map(|extension| extension.to_string())
.map(str::to_string)
}

0 comments on commit a8ae302

Please sign in to comment.