From 850b4579a8dc4b027abee1d9a92a0a3531841151 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 31 Oct 2015 20:20:04 +0100 Subject: [PATCH] Add type "File" to load a file from disk --- src/storage/file.rs | 39 +++++++++++++++++++++++++++++++++++++++ src/storage/parser.rs | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/storage/file.rs b/src/storage/file.rs index 86faca14..ff76bde3 100644 --- a/src/storage/file.rs +++ b/src/storage/file.rs @@ -2,6 +2,8 @@ use std::error::Error; use std::fmt::{Debug, Display, Formatter}; use std::fmt; +use super::parser::{FileHeaderParser, FileDataParser, Parser, ParserError}; + #[derive(Debug)] pub enum FileHeaderSpec { Null, @@ -165,3 +167,40 @@ pub fn match_header_spec<'a>(spec: &'a FileHeaderSpec, data: &'a FileHeaderData) None } +pub type FileID = String; + +pub struct File { + header : FileHeaderData, + data : D, + id : String +} + +impl File { + + fn new(prs: &Parser, path: &String) -> Result, ParserError> + where HP: FileHeaderParser, + DP: FileDataParser, + { + 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), + })) + } + + fn getID(&self) -> FileID { + self.id.clone() + } + + fn get_id_from_path(p: &String) -> FileID { + String::from("") + } + + fn read_file(p: &String) -> Result { + Ok(String::from("")) + } + +} + diff --git a/src/storage/parser.rs b/src/storage/parser.rs index 4d278d5f..2330a58e 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::*; +use super::file::{FileHeaderSpec, FileHeaderData, FileData}; pub struct ParserError { summary: String,