From 9e3d8497b50b3f20e6684e1bdb986661ac58abcf Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Sat, 27 May 2023 23:32:04 +0200 Subject: [PATCH] Fix --- .../services/book_library/formaters.rs | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/bots/approved_bot/services/book_library/formaters.rs b/src/bots/approved_bot/services/book_library/formaters.rs index 631ac9e..00d18a9 100644 --- a/src/bots/approved_bot/services/book_library/formaters.rs +++ b/src/bots/approved_bot/services/book_library/formaters.rs @@ -45,6 +45,10 @@ impl FormatInline for Translator { } fn format_authors(authors: Vec, count: usize) -> String { + if count == 0 { + return "".to_string() + } + match !authors.is_empty() { true => { let formated_authors = authors.clone()[..min(count, authors.len())] @@ -61,6 +65,10 @@ fn format_authors(authors: Vec, count: usize) -> String { } fn format_translators(translators: Vec, count: usize) -> String { + if count == 0 { + return "".to_string() + } + match !translators.is_empty() { true => { let formated_translators = translators.clone()[..min(count, translators.len())] @@ -77,6 +85,10 @@ fn format_translators(translators: Vec, count: usize) -> String { } fn format_sequences(sequences: Vec, count: usize) -> String { + if count == 0 { + return "".to_string() + } + match !sequences.is_empty() { true => { let formated_sequences: String = sequences.clone()[..min(count, sequences.len())] @@ -93,6 +105,10 @@ fn format_sequences(sequences: Vec, count: usize) -> String { } fn format_genres(genres: Vec, count: usize) -> String { + if count == 0 { + return "".to_string() + } + match !genres.is_empty() { true => { let formated_genres: String = genres.clone()[..min(count, genres.len())] @@ -180,17 +196,6 @@ impl FormatVectorsCounts { fn sub(self) -> Self { let Self {mut authors, mut translators, mut sequences, mut genres} = self; - if translators > 0 { - translators -= 1; - - return Self { - authors, - translators, - sequences, - genres - } - } - if genres > 0 { genres -= 1; @@ -213,6 +218,17 @@ impl FormatVectorsCounts { } } + if translators > 0 { + translators -= 1; + + return Self { + authors, + translators, + sequences, + genres + } + } + if authors > 0 { authors -= 1;