Implement FromStr for FileIDType

This commit is contained in:
Marcel Müller 2015-12-27 18:19:13 +01:00 committed by Matthias Beyer
parent 65aa98607e
commit 22b57d5ad9
2 changed files with 14 additions and 6 deletions

View file

@ -4,6 +4,7 @@ use std::fmt::{Debug, Display, Formatter};
use std::fmt;
use std::path::PathBuf;
use std::result::Result;
use std::str::FromStr;
use regex::Regex;
@ -58,12 +59,12 @@ impl FileID {
debug!(" Hash Name: {:?}", hashname);
debug!(" Hash: {:?}", hash);
FileIDType::parse(hashname).map(|idtype| {
FileIDType::from_str(hashname).map(|idtype| {
Some(FileID {
id: FileHash::from(hash),
id_type: idtype,
})
})
}).ok()
}).unwrap_or({
debug!("Did not match");
debug!("It is no path, actually. So we assume it is an ID already");

View file

@ -1,5 +1,6 @@
use std::convert::{From, Into};
use std::error::Error;
use std::str::FromStr;
#[derive(Debug)]
#[derive(Clone)]
@ -10,12 +11,18 @@ pub enum FileIDType {
UUID,
}
impl FileIDType {
pub fn parse(s: &str) -> Option<FileIDType> {
unimplemented!()
pub enum FileIDTypeParseError {
UnknownType
}
impl FromStr for FileIDType {
type Err = FileIDTypeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"UUID" => Ok(FileIDType::UUID),
_ => Err(FileIDTypeParseError::UnknownType)
}
}
}
impl Into<String> for FileIDType {