From ed58ef4d264f5ea1d68a202b3d5ab72dbfead31a Mon Sep 17 00:00:00 2001 From: Michal S Date: Mon, 5 Sep 2022 14:32:26 +0100 Subject: [PATCH] Make description an Option and handle it in Display/Printable --- src/operations/search.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/operations/search.rs b/src/operations/search.rs index 11f3302..bef2fc8 100644 --- a/src/operations/search.rs +++ b/src/operations/search.rs @@ -24,7 +24,7 @@ pub struct PackageSearchResult { pub groups: Option>, pub out_of_date: Option, pub installed: bool, - pub description: String, + pub description: Option, } impl PackageSearchResult { @@ -58,7 +58,13 @@ impl Display for PackageSearchResult { } else { "".to_string() }; - let description = wrap_text(&self.description, 4).join("\n"); + let description = wrap_text( + self.description + .clone() + .unwrap_or_else(|| "No description".to_string()), + 4, + ) + .join("\n"); format!("{repo}{name} {version}{groups}{out_of_date}{installed}\n {description}").fmt(f) } @@ -99,7 +105,13 @@ impl Printable for PackageSearchResult { } .bold() .cyan(); - let description = wrap_text(&self.description, 4).join("\n"); + let description = wrap_text( + self.description + .clone() + .unwrap_or_else(|| "No description".to_string()), + 4, + ) + .join("\n"); format!("{repo}{name} {version}{groups}{out_of_date}{installed}\n {description}") } @@ -137,7 +149,7 @@ pub async fn aur_search( groups, out_of_date, installed, - description: description.unwrap_or_else(|| "No description".to_string()), + description, } }) .collect(); @@ -176,7 +188,7 @@ pub async fn repo_search(query: &str, options: Options) -> Vec