Struct crowbook::BookOptions
[−]
[src]
pub struct BookOptions { pub root: PathBuf, // some fields omitted }
Contains the options of a book.
Fields
root: PathBuf
Root path of the book (unnecessary copy :/)
Methods
impl BookOptions
[src]
fn new() -> BookOptions
Creates a new BookOptions struct from the default compliled string
fn set_yaml(&mut self, key: Yaml, value: Yaml) -> Result<Option<BookOption>>
Sets an option from a Yaml tuple
Arguments
key
: the identifier of the option, must be Yaml::String(_)value
: the value of the option
Returns an error if key
is not a String, not a valid option, of if
the value is not of the right type.
fn set(&mut self, key: &str, value: &str) -> Result<Option<BookOption>>
Sets an option
Arguments
key
: the identifier of the option, e.g.: "author"value
: the value of the option as a string
Returns an error either if key
is not a valid option or if the
value is not of the right type. An option containing None if key was
not set, and Some(previous_value) if key was already present.
Examples
use crowbook::Book; let mut book = Book::new(&[]); book.options.set("author", "Joan Doe").unwrap(); // ok book.options.set("numbering", "2").unwrap(); // sets numbering to chapters and subsections let result = book.options.set("autor", "John Smith"); assert!(result.is_err()); // error: "author" was mispelled "autor" let result = book.options.set("numbering", "foo"); assert!(result.is_err()); // error: numbering must be an int
fn get(&self, key: &str) -> Result<&BookOption>
Gets an option
fn get_paths_list(&self, key: &str) -> Result<Vec<String>>
Gets a list of path. Only used for resources.files.
fn get_str(&self, key: &str) -> Result<&str>
Gets a string option
fn get_path(&self, key: &str) -> Result<String>
Get a path option
Adds book's root path before it
fn get_relative_path(&self, key: &str) -> Result<&str>
Get a path option
Don't add book's root path before it
fn get_bool(&self, key: &str) -> Result<bool>
gets a bool option
fn get_char(&self, key: &str) -> Result<char>
gets a char option
fn get_i32(&self, key: &str) -> Result<i32>
gets an int option
fn description(md: bool) -> String
Returns a description of all options valid to pass to a book.
arguments
md
: whether the output should be formatted in Markdown