Add file header types
for specifying header structure and parsing it from "raw" text.
This commit is contained in:
parent
a203b7af95
commit
ec1df06b24
1 changed files with 54 additions and 0 deletions
|
@ -54,3 +54,57 @@ pub trait Module {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub mod file {
|
||||||
|
|
||||||
|
pub struct ParserError {
|
||||||
|
summary: String,
|
||||||
|
parsertext: String,
|
||||||
|
index: i32,
|
||||||
|
explanation: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod header {
|
||||||
|
|
||||||
|
pub enum FileHeaderSpec {
|
||||||
|
Null,
|
||||||
|
Bool,
|
||||||
|
Integer,
|
||||||
|
UInteger,
|
||||||
|
Float,
|
||||||
|
Text,
|
||||||
|
Key { name: String, value_type: Box<FileHeaderSpec> },
|
||||||
|
Array { allowed_types: Box<Vec<FileHeaderSpec>> },
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum FileHeaderData {
|
||||||
|
Null,
|
||||||
|
Bool(bool),
|
||||||
|
Integer(i64),
|
||||||
|
UInteger(u64),
|
||||||
|
Float(f64),
|
||||||
|
Text(String),
|
||||||
|
Key { name: String, value: Box<FileHeaderData> },
|
||||||
|
Array { values: Box<Vec<FileHeaderData>> },
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait FileHeaderParser {
|
||||||
|
fn new(spec: &FileHeaderSpec) -> Self;
|
||||||
|
fn read(&self, string: &String) -> Result<FileHeaderData, super::ParserError>;
|
||||||
|
fn write(&self, data: &FileHeaderData) -> Result<String, super::ParserError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait FileData {
|
||||||
|
fn get_fulltext(&self) -> String;
|
||||||
|
fn get_abbrev(&self) -> String;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait FileParser {
|
||||||
|
fn new(header_parser: &header::FileHeaderParser) -> FileParser;
|
||||||
|
fn read(&self, string: String) -> (header::FileHeaderData, FileData);
|
||||||
|
fn write(&self, hdr: &header::FileHeaderData, data: &FileData) -> Result<String, ParserError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue