Add StoreId::local_display_string() function

for safely creating a `String` object from `StoreId` which can be shown
to the user.

Mainly introduced because this is useful for error handling (when
putting a `StoreId` into an error kind, the compiler complains that
`StoreId` does not meet the required trait bounds. But `String` does and
we do not process the ID any further anyways).

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2018-10-13 11:51:15 +02:00
parent 05d43128ce
commit d87ea7b305

View file

@ -128,6 +128,18 @@ impl StoreId {
.ok_or_else(|| SE::from_kind(SEK::StoreIdHandlingError)) .ok_or_else(|| SE::from_kind(SEK::StoreIdHandlingError))
} }
/// Helper function for creating a displayable String from StoreId
///
/// This is safe because the
///
/// impl<T: fmt::Display + ?Sized> ToString for T
///
/// does only fail if Display::display() failed. The implementation of ::std::path::Display and
/// the implementation ::std::fmt::Display for ::std::path::Display do not return errors though.
pub fn local_display_string(&self) -> String {
self.local().display().to_string()
}
/// Returns the components of the `id` part of the StoreId object. /// Returns the components of the `id` part of the StoreId object.
/// ///
/// Can be used to check whether a StoreId points to an entry in a specific collection of /// Can be used to check whether a StoreId points to an entry in a specific collection of