From 6ad32c1f6a2641eb33e18150dddf52afd14348f3 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Tue, 17 Dec 2024 11:58:31 -0800 Subject: [PATCH] switch to using name_str --- src/core/src/manifest.rs | 2 +- src/core/src/signature.rs | 7 ++++++- src/core/src/storage/mod.rs | 4 ++-- src/core/tests/storage.rs | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/src/manifest.rs b/src/core/src/manifest.rs index 92580a3bb..4a49808f6 100644 --- a/src/core/src/manifest.rs +++ b/src/core/src/manifest.rs @@ -129,7 +129,7 @@ impl Record { Self { internal_location: path.into(), moltype: moltype.to_string(), - name: sig.name().unwrap_or("".into()), + name: sig.name_str(), ksize, md5, md5short, diff --git a/src/core/src/signature.rs b/src/core/src/signature.rs index e06e15df2..f00a5f7b0 100644 --- a/src/core/src/signature.rs +++ b/src/core/src/signature.rs @@ -453,6 +453,11 @@ impl Signature { } } + // return name, if not None; or "" if None. + pub fn name_str(&self) -> String { + self.name().unwrap_or("".into()) + } + pub fn set_name(&mut self, name: &str) { self.name = Some(name.into()) } @@ -981,7 +986,7 @@ mod test { assert_eq!(sig.signatures[1].size(), 2); assert_eq!(sig.signatures[2].size(), 1); - assert_eq!(sig.name().unwrap_or("".into()), ""); + assert_eq!(sig.name_str(), ""); } #[test] diff --git a/src/core/src/storage/mod.rs b/src/core/src/storage/mod.rs index b8836217b..94b5fb815 100644 --- a/src/core/src/storage/mod.rs +++ b/src/core/src/storage/mod.rs @@ -466,7 +466,7 @@ impl ZipStorage { impl SigStore { pub fn new_with_storage(sig: Signature, storage: InnerStorage) -> Self { - let name = sig.name().unwrap_or("".into()); + let name = sig.name_str(); let filename = sig.filename(); SigStore::builder() @@ -555,7 +555,7 @@ impl Deref for SigStore { impl From for SigStore { fn from(other: Signature) -> SigStore { - let name = other.name().unwrap_or("".into()); + let name = other.name_str(); let filename = other.filename(); SigStore::builder() diff --git a/src/core/tests/storage.rs b/src/core/tests/storage.rs index ebf33cb25..68a04ccc7 100644 --- a/src/core/tests/storage.rs +++ b/src/core/tests/storage.rs @@ -98,7 +98,7 @@ fn innerstorage_save_sig() -> Result<(), Box> { let loaded_sig = instorage.load_sig("test")?; - assert_eq!(sig.name().unwrap_or("".into()), loaded_sig.name()); + assert_eq!(sig.name_str(), loaded_sig.name()); assert_eq!(sig.md5sum(), loaded_sig.md5sum()); Ok(())