From bd1fb7afd2e0e965989dcfbffc2ff7f4ef828d5d Mon Sep 17 00:00:00 2001 From: Vika Date: Sat, 7 Sep 2024 16:47:23 +0300 Subject: Reduce unwraps in u-ate and u-drank handling --- templates/src/mf2.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/templates/src/mf2.rs b/templates/src/mf2.rs index 076989c..550adfc 100644 --- a/templates/src/mf2.rs +++ b/templates/src/mf2.rs @@ -237,15 +237,15 @@ markup::define! { } @if post["properties"]["ate"].is_array() || post["properties"]["drank"].is_array() { div { - @if post["properties"]["ate"].is_array() { + @if let Some(ate) = post["properties"]["ate"].as_array() { span { ul { "Ate:" - @for food in post["properties"]["ate"].as_array().unwrap() { + @for food in ate { li { - @if food.is_string() { + @if let Some(food) = food.as_str() { // If this is a string, it's a URL. - a."u-ate"[href=food.as_str().unwrap()] { - @food.as_str().unwrap().truncate_ellipse(24).as_ref() + a."u-ate"[href=food] { + @food.truncate_ellipse(24).as_ref() } } else { // This is a rich food object (mm, sounds tasty! I wanna eat something tasty) @@ -258,15 +258,15 @@ markup::define! { } } } } - @if post["properties"]["drank"].is_array() { + @if let Some(drank) = post["properties"]["drank"].as_array() { span { ul { "Drank:" - @for food in post["properties"]["drank"].as_array().unwrap() { + @for food in drank { li { - @if food.is_string() { + @if let Some(food) = food.as_str() { // If this is a string, it's a URL. - a."u-drank"[href=food.as_str().unwrap()] { - @food.as_str().unwrap().truncate_ellipse(24).as_ref() + a."u-drank"[href=food] { + @food.truncate_ellipse(24).as_ref() } } else { // This is a rich food object (mm, sounds tasty! I wanna eat something tasty) -- cgit 1.4.1