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,16 +95,14 @@ impl StoreId {
}
pub fn to_str(&self) -> Result<String> {
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.