From 799b9e27a50e0cc52a78d48a9c4159aacf9d4773 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 14 Apr 2016 13:20:35 +0200 Subject: [PATCH] Remove typedef for StoreId type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Matthias Beyer --- libimagstore/src/storeid.rs | 46 ++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/libimagstore/src/storeid.rs b/libimagstore/src/storeid.rs index 7c5940c1..87f432e7 100644 --- a/libimagstore/src/storeid.rs +++ b/libimagstore/src/storeid.rs @@ -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 for StoreId { + + fn into(self) -> PathBuf { + self.0 + } + +} + +impl From for StoreId { + + fn from(pb: PathBuf) -> StoreId { + StoreId(pb) + } + +} + +impl From for StoreId { + + fn from(string: String) -> StoreId { + StoreId(string.into()) + } + +} + +impl AsRef for StoreId { + + fn as_ref(&self) -> &Path { + self.0.as_ref() + } + +} + +impl Borrow 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