Add doc to module header helpers

This commit is contained in:
Matthias Beyer 2015-12-29 17:04:35 +01:00
parent e9cee25ac8
commit ffcb951468
2 changed files with 43 additions and 2 deletions

View file

@ -1,13 +1,23 @@
/* /*!
* Helpers for headers * Helpers for headers
*/ */
pub mod tags; pub mod tags;
/**
* Utility helpers for header data
*/
pub mod data { pub mod data {
use std::ops::Deref; use std::ops::Deref;
use storage::file::header::data::FileHeaderData as FHD; use storage::file::header::data::FileHeaderData as FHD;
/**
* Get an URL from a header, whereas the header has to have the following format:
*
* { ..., "URL": "<URL>", ... }
*
* Does no spec verification.
*/
pub fn get_url_from_header(header: &FHD) -> Option<String> { pub fn get_url_from_header(header: &FHD) -> Option<String> {
match header { match header {
&FHD::Map{keys: ref ks} => { &FHD::Map{keys: ref ks} => {

View file

@ -1,30 +1,61 @@
/* /*!
* Helpers for headers - Tags * Helpers for headers - Tags
*/ */
/**
* Spec helpers for header-tags
*/
pub mod spec { pub mod spec {
use storage::file::header::spec::FileHeaderSpec as FHS; use storage::file::header::spec::FileHeaderSpec as FHS;
use module::helpers::spec::{named_text, named_text_array}; use module::helpers::spec::{named_text, named_text_array};
/**
* helper for a Header spec for
*
* { "URL": "<Text>" }
*/
pub fn url_key() -> FHS { pub fn url_key() -> FHS {
named_text("URL") named_text("URL")
} }
/**
* helper for a Header spec for
*
* { "TAGS": [ "<Text>", ... ] }
*/
pub fn tags_key() -> FHS { pub fn tags_key() -> FHS {
named_text_array("TAGS") named_text_array("TAGS")
} }
} }
/**
* Data helpers for header-tags
*/
pub mod data { pub mod data {
use std::ops::Deref; use std::ops::Deref;
use storage::file::header::data::FileHeaderData as FHD; use storage::file::header::data::FileHeaderData as FHD;
/**
* Use a Vec<String> to build a Tag-Array:
*
* [ "<Text>", ... ]
*/
pub fn build_tag_array(tags: Vec<String>) -> FHD { pub fn build_tag_array(tags: Vec<String>) -> FHD {
let texttags = tags.into_iter().map(|t| FHD::Text(t.clone())).collect(); let texttags = tags.into_iter().map(|t| FHD::Text(t.clone())).collect();
FHD::Array { values: Box::new(texttags) } FHD::Array { values: Box::new(texttags) }
} }
/**
* Fetch tags from a header, whereas the header looks like this:
*
* { ...,
* "TAGS": [ "<Text>", ... ],
* ...
* }
*
* Does no spec verification.
*/
pub fn get_tags_from_header(header: &FHD) -> Vec<String> { pub fn get_tags_from_header(header: &FHD) -> Vec<String> {
let mut tags : Vec<String> = vec![]; let mut tags : Vec<String> = vec![];