From 5b65175710a19daf43c81e52e180fd66ecfe4353 Mon Sep 17 00:00:00 2001 From: Vika Date: Tue, 4 May 2021 23:12:59 +0300 Subject: Clippy lints --- src/micropub/post.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/micropub') diff --git a/src/micropub/post.rs b/src/micropub/post.rs index 7ec3566..37cbe26 100644 --- a/src/micropub/post.rs +++ b/src/micropub/post.rs @@ -40,7 +40,7 @@ fn get_folder_from_type(post_type: &str) -> String { }).to_string() } -fn normalize_mf2<'a>(mut body: serde_json::Value, user: &User) -> (String, serde_json::Value) { +fn normalize_mf2(mut body: serde_json::Value, user: &User) -> (String, serde_json::Value) { // Normalize the MF2 object here. let me = &user.me; let published: DateTime; @@ -91,7 +91,7 @@ fn normalize_mf2<'a>(mut body: serde_json::Value, user: &User) -> (String, serde match body["properties"]["url"].as_array_mut() { Some(array) => { if !array.iter().any(|i| i.as_str().unwrap_or("") == uid) { - array.push(serde_json::Value::String(uid.to_string())) + array.push(serde_json::Value::String(uid)) } } None => { @@ -126,7 +126,7 @@ fn normalize_mf2<'a>(mut body: serde_json::Value, user: &User) -> (String, serde body["properties"]["channel"] = json!([default_channel]); } body["properties"]["posted-with"] = json!([user.client_id]); - if let None = body["properties"]["author"][0].as_str() { + if body["properties"]["author"][0].as_str().is_none() { body["properties"]["author"] = json!([me.as_str()]) } // TODO: maybe highlight #hashtags? @@ -168,7 +168,7 @@ async fn new_post(req: Request>, body: serde_jso for channel in post["properties"]["channel"] .as_array().unwrap().iter() .map(|i| i.as_str().unwrap_or("").to_string()) - .filter(|i| i != "") + .filter(|i| !i.is_empty()) .collect::>() { let default_channel = user.me.join(DEFAULT_CHANNEL_PATH).unwrap().to_string(); @@ -243,9 +243,9 @@ async fn process_json(req: Request>, body: serde return error_json!(400, "invalid_request", "This action is not supported.") } } - } else if let Some(_) = body["type"][0].as_str() { + } else if body["type"][0].is_string() { // This is definitely an h-entry or something similar. Check if it has properties? - if let Some(_) = body["properties"].as_object() { + if body["properties"].is_object() { // Ok, this is definitely a new h-entry. Let's save it. return new_post(req, body).await } else { @@ -269,10 +269,10 @@ fn convert_form_to_mf2_json(form: Vec<(String, String)>) -> serde_json::Value { } } } - if mf2["type"].as_array().unwrap().len() == 0 { + if mf2["type"].as_array().unwrap().is_empty() { mf2["type"].as_array_mut().unwrap().push(json!("h-entry")); } - return mf2 + mf2 } async fn process_form(req: Request>, form: Vec<(String, String)>) -> Result { -- cgit 1.4.1