Optimize Rust code with Clippy

This commit is contained in:
spikecodes 2021-01-01 12:33:57 -08:00
parent 64a92195dd
commit d43b49e7e4
7 changed files with 71 additions and 73 deletions

View file

@ -19,7 +19,7 @@ pub async fn profile(req: HttpRequest) -> Result<HttpResponse> {
let path = format!("{}.json?{}&raw_json=1", req.path(), req.query_string());
// Retrieve other variables from Libreddit request
let sort = param(&path, "sort").await;
let sort = param(&path, "sort");
let username = req.match_info().get("username").unwrap_or("").to_string();
// Request user profile data and user posts/comments from Reddit
@ -35,8 +35,8 @@ pub async fn profile(req: HttpRequest) -> Result<HttpResponse> {
let s = UserTemplate {
user: user.unwrap(),
posts: posts_unwrapped.0,
sort: (sort, param(&path, "t").await),
ends: (param(&path, "after").await, posts_unwrapped.1),
sort: (sort, param(&path, "t")),
ends: (param(&path, "after"), posts_unwrapped.1),
}
.render()
.unwrap();
@ -50,7 +50,7 @@ pub async fn profile(req: HttpRequest) -> Result<HttpResponse> {
// }
// USER
async fn user(name: &String) -> Result<User, &'static str> {
async fn user(name: &str) -> Result<User, &'static str> {
// Build the Reddit JSON API path
let path: String = format!("user/{}/about.json", name);
@ -71,11 +71,11 @@ async fn user(name: &String) -> Result<User, &'static str> {
// Parse the JSON output into a User struct
Ok(User {
name: name.to_string(),
title: nested_val(&res, "subreddit", "title").await,
icon: format_url(nested_val(&res, "subreddit", "icon_img").await).await,
title: nested_val(&res, "subreddit", "title"),
icon: format_url(nested_val(&res, "subreddit", "icon_img")).await,
karma: res["data"]["total_karma"].as_i64().unwrap(),
created: Utc.timestamp(created, 0).format("%b %e, %Y").to_string(),
banner: nested_val(&res, "subreddit", "banner_img").await,
description: nested_val(&res, "subreddit", "public_description").await,
banner: nested_val(&res, "subreddit", "banner_img"),
description: nested_val(&res, "subreddit", "public_description"),
})
}