From 3d572dda0f4458cee3833350b8f6907c7422cc12 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 13 Oct 2016 14:31:32 +0200 Subject: [PATCH] Reimplement StoreId::to_str() to remove unwrap() --- libimagstore/src/storeid.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/libimagstore/src/storeid.rs b/libimagstore/src/storeid.rs index 5f979126..8a3623c8 100644 --- a/libimagstore/src/storeid.rs +++ b/libimagstore/src/storeid.rs @@ -95,16 +95,14 @@ impl StoreId { } pub fn to_str(&self) -> Result { - if self.base.is_some() { - let mut base = self.base.as_ref().cloned().unwrap(); - base.push(self.id.clone()); - base - } else { - self.id.clone() - } - .to_str() - .map(String::from) - .ok_or(SEK::StoreIdHandlingError.into_error()) + self.base + .as_ref() + .cloned() + .map(|mut base| { base.push(self.id.clone()); base }) + .unwrap_or_else(|| self.id.clone()) + .to_str() + .map(String::from) + .ok_or(SEK::StoreIdHandlingError.into_error()) } /// Returns the components of the `id` part of the StoreId object.