Reimplement StoreId::to_str() to remove unwrap()

This commit is contained in:
Matthias Beyer 2016-10-13 14:31:32 +02:00
parent 52367edc83
commit 3d572dda0f

View file

@ -95,13 +95,11 @@ impl StoreId {
} }
pub fn to_str(&self) -> Result<String> { pub fn to_str(&self) -> Result<String> {
if self.base.is_some() { self.base
let mut base = self.base.as_ref().cloned().unwrap(); .as_ref()
base.push(self.id.clone()); .cloned()
base .map(|mut base| { base.push(self.id.clone()); base })
} else { .unwrap_or_else(|| self.id.clone())
self.id.clone()
}
.to_str() .to_str()
.map(String::from) .map(String::from)
.ok_or(SEK::StoreIdHandlingError.into_error()) .ok_or(SEK::StoreIdHandlingError.into_error())