From 02da675b3f8b356278b2e379cf67f04b43094d78 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 3 Dec 2015 17:33:03 +0100 Subject: [PATCH 1/6] Impl Into for FileIDType --- src/storage/file_id.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/storage/file_id.rs b/src/storage/file_id.rs index 03e507e0..5d3ebb7e 100644 --- a/src/storage/file_id.rs +++ b/src/storage/file_id.rs @@ -18,6 +18,19 @@ pub enum FileIDType { UUID, } +impl Into for FileIDType { + + fn into(self) -> String { + let s = match self { + FileIDType::UUID => "UUID", + FileIDType::NONE => "", + }; + + String::from(s) + } + +} + #[derive(Clone)] pub struct FileID { id: Option, From 445f543159c89d0a4e444461002eef2325e324d4 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 3 Dec 2015 17:33:16 +0100 Subject: [PATCH 2/6] Impl From for FileIDType --- src/storage/file_id.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/storage/file_id.rs b/src/storage/file_id.rs index 5d3ebb7e..014ad3e6 100644 --- a/src/storage/file_id.rs +++ b/src/storage/file_id.rs @@ -31,6 +31,17 @@ impl Into for FileIDType { } +impl From for FileIDType { + + fn from(s: String) -> FileIDType { + match &s[..] { + "UUID" => FileIDType::UUID, + _ => FileIDType::NONE, + } + } + +} + #[derive(Clone)] pub struct FileID { id: Option, From 5c3d0ecce78254e9ab52692924bc10bec0b8f331 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 3 Dec 2015 17:33:29 +0100 Subject: [PATCH 3/6] Impl Into for FileID --- src/storage/file_id.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/storage/file_id.rs b/src/storage/file_id.rs index 014ad3e6..6bbc4ea1 100644 --- a/src/storage/file_id.rs +++ b/src/storage/file_id.rs @@ -101,6 +101,13 @@ impl Into for FileID { } +impl Into for FileID { + + fn into(self) -> FileIDType { + self.id_type.clone() + } +} + impl From for FileID { fn from(s: String) -> FileID { From f25e3683a1520e0c597f608dc53e17b406536a69 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 3 Dec 2015 17:33:48 +0100 Subject: [PATCH 4/6] Add hash type to filepath --- src/storage/backend.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/storage/backend.rs b/src/storage/backend.rs index 4d59c539..40ace0f0 100644 --- a/src/storage/backend.rs +++ b/src/storage/backend.rs @@ -224,12 +224,20 @@ impl StorageBackend { } fn build_filepath_with_id(&self, owner: &Module, id: FileID) -> String { + let idstr : String = id.clone().into(); + let idtype : FileIDType = id.into(); + let typestr : String = idtype.into(); + debug!("Building filepath with id"); debug!(" basepath: '{}'", self.basepath); debug!(" storepath: '{}'", self.storepath); - debug!(" id : '{}'", id); - let idstr : String = id.into(); - self.prefix_of_files_for_module(owner) + "-" + &idstr[..] + ".imag" + debug!(" id: '{}'", idstr); + debug!(" type: '{}'", typestr); + + self.prefix_of_files_for_module(owner) + + "-" + &typestr[..] + + "-" + &idstr[..] + + ".imag" } fn prefix_of_files_for_module(&self, m: &Module) -> String { From ce4d99384bee1d247da2e668e8ff78b5f48018b9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 3 Dec 2015 17:36:52 +0100 Subject: [PATCH 5/6] Impl From<&str> for FileIDType, use implementation in From for FileIDType --- src/storage/file_id.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/storage/file_id.rs b/src/storage/file_id.rs index 6bbc4ea1..645669b7 100644 --- a/src/storage/file_id.rs +++ b/src/storage/file_id.rs @@ -31,10 +31,10 @@ impl Into for FileIDType { } -impl From for FileIDType { +impl<'a> From<&'a str> for FileIDType { - fn from(s: String) -> FileIDType { - match &s[..] { + fn from(s: &'a str) -> FileIDType { + match s { "UUID" => FileIDType::UUID, _ => FileIDType::NONE, } @@ -42,6 +42,14 @@ impl From for FileIDType { } +impl From for FileIDType { + + fn from(s: String) -> FileIDType { + FileIDType::from(&s[..]) + } + +} + #[derive(Clone)] pub struct FileID { id: Option, From 1b0f4894acf11de53bf0c7687ed064daf4cfbba7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 3 Dec 2015 17:37:13 +0100 Subject: [PATCH 6/6] Use FileIDType::from() and remove select_id_type_from_str() --- src/storage/file_id.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/storage/file_id.rs b/src/storage/file_id.rs index 645669b7..afc28c0c 100644 --- a/src/storage/file_id.rs +++ b/src/storage/file_id.rs @@ -151,7 +151,7 @@ impl<'a> From<&'a String> for FileID { debug!(" Hash Name: {:?}", hashname); debug!(" Hash: {:?}", hash); - let idtype = select_id_type_from_str(hashname); + let idtype = FileIDType::from(hashname); match idtype { FileIDType::NONE => hash = "INVALID", _ => {}, @@ -231,13 +231,6 @@ impl<'a> Display for FileIDError { } -fn select_id_type_from_str(s: &str) -> FileIDType { - match s { - "UUID" => FileIDType::UUID, - _ => FileIDType::NONE, - } -} - pub type FileIDResult = Result; #[cfg(test)]