From e7e2ae5b0579c8f340d8d49632179998618a09a0 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Sat, 12 Oct 2024 15:10:47 -0700 Subject: [PATCH] wip tryinto minhash for signature --- src/core/src/signature.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/core/src/signature.rs b/src/core/src/signature.rs index 8cc4ba915..f68852dd0 100644 --- a/src/core/src/signature.rs +++ b/src/core/src/signature.rs @@ -887,6 +887,28 @@ impl PartialEq for Signature { } } +impl TryInto for Signature { + type Error = crate::Error; + + fn try_into(self) -> Result { + match self.signatures.len() { + 1 => self + .signatures + .into_iter() + .find_map(|sk| { + if let Sketch::MinHash(mh) = sk { + Some(mh) + } else { + None + } + }) + .ok_or_else(|| todo!("error, no minhash found")), + 0 => todo!("error, empty signature"), + 2.. => todo!("Multiple sketches found! Please run select first."), + } + } +} + #[cfg(test)] mod test { use std::fs::File;