Add type "File" to load a file from disk
This commit is contained in:
parent
111a990b99
commit
850b4579a8
2 changed files with 40 additions and 1 deletions
|
@ -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<D: FileData> {
|
||||
header : FileHeaderData,
|
||||
data : D,
|
||||
id : String
|
||||
}
|
||||
|
||||
impl<D: FileData> File<D> {
|
||||
|
||||
fn new<HP, DP>(prs: &Parser<HP, DP>, path: &String) -> Result<File<D>, ParserError>
|
||||
where HP: FileHeaderParser,
|
||||
DP: FileDataParser<D>,
|
||||
{
|
||||
File::<D>::read_file(path).and_then(|p| prs.read(p))
|
||||
.and_then(|(h, d)|
|
||||
Ok(File {
|
||||
header: h,
|
||||
data: d,
|
||||
id: File::<D>::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<String, ParserError> {
|
||||
Ok(String::from(""))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue