Outsource file id parsing

This commit is contained in:
Matthias Beyer 2015-11-23 18:42:55 +01:00
parent b0e5f28528
commit 9aced858ac
4 changed files with 22 additions and 13 deletions

View file

@ -9,7 +9,8 @@ use std::vec::Vec;
use glob::glob; use glob::glob;
use glob::Paths; use glob::Paths;
use storage::file::{File, FileID}; use storage::file::File;
use storage::file_id::*;
use module::Module; use module::Module;
type BackendOperationResult = Result<(), StorageBackendError>; type BackendOperationResult = Result<(), StorageBackendError>;
@ -35,7 +36,7 @@ impl<'a> StorageBackend<'a> {
let mut v = vec![]; let mut v = vec![];
for entry in globlist { for entry in globlist {
if let Ok(path) = entry { if let Ok(path) = entry {
v.push(file_id_from_path(path.as_path())); v.push(from_pathbuf(&path));
} else { } else {
// Entry is not a path // Entry is not a path
} }
@ -66,10 +67,6 @@ impl<'a> StorageBackend<'a> {
} }
fn file_id_from_path(p: &Path) -> String {
String::from("")
}
#[derive(Debug)] #[derive(Debug)]
pub struct StorageBackendError { pub struct StorageBackendError {
pub action: String, // The file system action in words pub action: String, // The file system action in words

View file

@ -3,6 +3,7 @@ use std::fmt::{Debug, Display, Formatter};
use std::fmt; use std::fmt;
use super::parser::{FileHeaderParser, Parser, ParserError}; use super::parser::{FileHeaderParser, Parser, ParserError};
use storage::file_id::*;
#[derive(Debug)] #[derive(Debug)]
pub enum FileHeaderSpec { pub enum FileHeaderSpec {
@ -162,8 +163,6 @@ pub fn match_header_spec<'a>(spec: &'a FileHeaderSpec, data: &'a FileHeaderData)
None None
} }
pub type FileID = String;
pub struct File { pub struct File {
header : FileHeaderData, header : FileHeaderData,
data : String, data : String,
@ -180,7 +179,7 @@ impl<'a> File {
Ok(File { Ok(File {
header: h, header: h,
data: d, data: d,
id: File::get_id_from_path(path), id: from_path_string(path),
})) }))
} }
@ -188,10 +187,6 @@ impl<'a> File {
self.id.clone() self.id.clone()
} }
fn get_id_from_path(p: &String) -> FileID {
String::from("")
}
fn read_file(p: &String) -> Result<String, ParserError> { fn read_file(p: &String) -> Result<String, ParserError> {
Ok(String::from("")) Ok(String::from(""))
} }

16
src/storage/file_id.rs Normal file
View file

@ -0,0 +1,16 @@
use std::path::{Path, PathBuf};
pub type FileID = String;
pub fn from_path_string(s: &String) -> FileID {
String::from("")
}
pub fn from_path(p: &Path) -> FileID {
String::from("")
}
pub fn from_pathbuf(p: &PathBuf) -> FileID {
from_path(p.as_path())
}

View file

@ -5,6 +5,7 @@ pub use std::error::Error;
pub use runtime::Runtime; pub use runtime::Runtime;
pub mod file; pub mod file;
pub mod file_id;
pub mod parser; pub mod parser;
pub mod backend; pub mod backend;