Remove typedef for StoreId type

but make it a new type instead.

Also derive and implement as many traits as possible for it, so we keep
backwards compatibility as much as possible.

Anyways, we need to rewrite some code for this.

Suggested-by: Marcel Müller <neikos@neikos.email>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2016-04-14 13:20:35 +02:00
parent 1f13594999
commit 799b9e27a5

View file

@ -1,4 +1,7 @@
use std::path::PathBuf;
use std::path::Path;
use std::borrow::Borrow;
use glob::Paths;
use semver::Version;
use std::fmt::{Debug, Formatter};
@ -10,7 +13,48 @@ use store::Result;
use store::Store;
/// The Index into the Store
pub type StoreId = PathBuf;
#[derive(Debug, Clone, PartialEq, Hash, Eq, PartialOrd, Ord)]
pub struct StoreId(PathBuf);
impl Into<PathBuf> for StoreId {
fn into(self) -> PathBuf {
self.0
}
}
impl From<PathBuf> for StoreId {
fn from(pb: PathBuf) -> StoreId {
StoreId(pb)
}
}
impl From<String> for StoreId {
fn from(string: String) -> StoreId {
StoreId(string.into())
}
}
impl AsRef<Path> for StoreId {
fn as_ref(&self) -> &Path {
self.0.as_ref()
}
}
impl Borrow<Path> for StoreId {
fn borrow(&self) -> &Path {
self.0.borrow()
}
}
/// This Trait allows you to convert various representations to a single one
/// suitable for usage in the Store