From a5d4b74298520c72156afb3efffa7eac1ece645c Mon Sep 17 00:00:00 2001 From: Cyril Marpaud Date: Tue, 3 Oct 2023 14:43:00 +0200 Subject: [PATCH] feat: avoid an allocation --- kepler/src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kepler/src/main.rs b/kepler/src/main.rs index 8d28250..a6da2ac 100644 --- a/kepler/src/main.rs +++ b/kepler/src/main.rs @@ -4,6 +4,7 @@ use domain_db::{cve_sources::nist, db}; use dotenvy::dotenv; use env_logger::Env; use lazy_static::lazy_static; +use std::borrow::Cow; use std::{fs, path::Path}; mod api; @@ -184,11 +185,11 @@ pub fn import_nist( Ok(num_imported) } -fn report_message(num_records: u32) -> String { +fn report_message(num_records: u32) -> Cow<'static, str> { if num_records == 0 { - "No new records created".to_string() + Cow::Borrowed("No new records created") } else { - format!("{num_records} new records created") + Cow::Owned(format!("{num_records} new records created")) } }