Add interface for header field addressing by str

This commit is contained in:
Matthias Beyer 2016-01-27 10:37:43 +01:00
parent e9528fdd33
commit 2f6cfb5868
2 changed files with 80 additions and 0 deletions

View file

@ -24,6 +24,7 @@ pub enum StoreErrorKind {
EntryAlreadyBorrowed, EntryAlreadyBorrowed,
EntryAlreadyExists, EntryAlreadyExists,
MalformedEntry, MalformedEntry,
HeaderPathSyntaxError,
// maybe more // maybe more
} }
@ -44,6 +45,7 @@ fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str {
&StoreErrorKind::EntryAlreadyBorrowed => "Entry is already borrowed", &StoreErrorKind::EntryAlreadyBorrowed => "Entry is already borrowed",
&StoreErrorKind::EntryAlreadyExists => "Entry already exists", &StoreErrorKind::EntryAlreadyExists => "Entry already exists",
&StoreErrorKind::MalformedEntry => "Entry has invalid formatting, missing header", &StoreErrorKind::MalformedEntry => "Entry has invalid formatting, missing header",
&StoreErrorKind::HeaderPathSyntaxError => "Syntax error in accessor string",
} }
} }

View file

@ -362,6 +362,84 @@ impl EntryHeader {
verify_header(&self.toml) verify_header(&self.toml)
} }
/**
* Insert a header field by a string-spec
*
* ```ignore
* insert("something.in.a.field", Boolean(true));
* ```
*
* Inserts a Boolean in the section "something" -> "in" -> "a" -> "field"
* A JSON equivalent would be
*
* {
* something: {
* in: {
* a: {
* field: true
* }
* }
* }
* }
*
* Returns true if header field was set, false if there is already a value
*/
pub fn insert(&mut self, spec: &str, v: Value) -> Result<bool> {
unimplemented!()
}
/**
* Set a header field by a string-spec
*
* ```ignore
* set("something.in.a.field", Boolean(true));
* ```
*
* Sets a Boolean in the section "something" -> "in" -> "a" -> "field"
* A JSON equivalent would be
*
* {
* something: {
* in: {
* a: {
* field: true
* }
* }
* }
* }
*
* If there is already a value at this place, this value will be overridden and the old value
* will be returned
*/
pub fn set(&mut self, spec: &str, v: Value) -> Result<Option<Value>> {
unimplemented!()
}
/**
* Read a header field by a string-spec
*
* ```ignore
* let value = read("something.in.a.field");
* ```
*
* Reads a Value in the section "something" -> "in" -> "a" -> "field"
* A JSON equivalent would be
*
* {
* something: {
* in: {
* a: {
* field: true
* }
* }
* }
* }
*
* If there is no a value at this place, None will be returned
*/
pub fn read(&self, spec: &str) -> Result<Option<Value>> {
unimplemented!()
}
} }
fn build_default_header() -> BTreeMap<String, Value> { fn build_default_header() -> BTreeMap<String, Value> {