diff --git a/src/storage/file.rs b/src/storage/file.rs index 008b2d9c..74413f4a 100644 --- a/src/storage/file.rs +++ b/src/storage/file.rs @@ -2,7 +2,7 @@ use std::error::Error; use std::fmt::{Debug, Display, Formatter}; use std::fmt; -use super::parser::{FileHeaderParser, FileDataParser, Parser, ParserError}; +use super::parser::{FileHeaderParser, Parser, ParserError}; #[derive(Debug)] pub enum FileHeaderSpec { @@ -30,11 +30,6 @@ pub enum FileHeaderData { Array { values: Box> }, } -pub trait FileData : Sized { - fn get_fulltext(&self) -> String; - fn get_abbrev(&self) -> String; -} - impl Display for FileHeaderSpec { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { @@ -169,24 +164,23 @@ pub fn match_header_spec<'a>(spec: &'a FileHeaderSpec, data: &'a FileHeaderData) pub type FileID = String; -pub struct File { +pub struct File { header : FileHeaderData, - data : D, + data : String, id : String } -impl<'a, D: FileData> File { +impl<'a> File { - fn new(prs: &Parser, path: &String) -> Result, ParserError> - where HP: FileHeaderParser<'a>, - DP: FileDataParser, + fn new(prs: &Parser, path: &String) -> Result + where HP: FileHeaderParser<'a> { - File::::read_file(path).and_then(|p| prs.read(p)) + File::read_file(path).and_then(|p| prs.read(p)) .and_then(|(h, d)| Ok(File { header: h, data: d, - id: File::::get_id_from_path(path), + id: File::get_id_from_path(path), })) } diff --git a/src/storage/parser.rs b/src/storage/parser.rs index 8013ef97..6ad7895e 100644 --- a/src/storage/parser.rs +++ b/src/storage/parser.rs @@ -3,7 +3,7 @@ use std::error::Error; use std::fmt::{Debug, Display, Formatter}; use std::fmt; -use super::file::{FileHeaderSpec, FileHeaderData, FileData}; +use super::file::{FileHeaderSpec, FileHeaderData}; pub struct ParserError { summary: String, @@ -80,34 +80,24 @@ pub trait FileHeaderParser<'a> : Sized { fn write(&self, data: &FileHeaderData) -> Result; } -pub trait FileDataParser : Sized { - fn new() -> Self; - fn read(&self, string: Option) -> Result; - fn write(&self, data: &FD) -> Result; -} - type TextTpl = (Option, Option); -pub struct Parser +pub struct Parser { headerp : HP, - datap : DP, } -impl<'a, HP, DP> Parser where +impl<'a, HP> Parser where HP: FileHeaderParser<'a>, { - fn new(headerp: HP, datap: DP) -> Parser { + fn new(headerp: HP) -> Parser { Parser { headerp: headerp, - datap: datap, } } - pub fn read(&self, s: String) -> Result<(FileHeaderData, FD), ParserError> - where FD: FileData + Sized, - DP: FileDataParser + pub fn read(&self, s: String) -> Result<(FileHeaderData, String), ParserError> { let divided = self.divide_text(&s); @@ -118,20 +108,16 @@ impl<'a, HP, DP> Parser where let (header, data) = divided.ok().unwrap(); let h_parseres = try!(self.headerp.read(header)); - let d_parseres = try!(self.datap.read(data)); - Ok((h_parseres, d_parseres)) + Ok((h_parseres, data.unwrap_or(String::new()))) } - fn write(&self, tpl : (FileHeaderData, FD)) -> Result - where FD: FileData + Sized, - DP: FileDataParser + fn write(&self, tpl : (FileHeaderData, String)) -> Result { let (header, data) = tpl; let h_text = try!(self.headerp.write(&header)); - let d_text = try!(self.datap.write(&data)); - Ok(h_text + &d_text[..]) + Ok(h_text + &data[..]) } fn divide_text(&self, text: &String) -> Result {