Struct crowbook::BookOptions
[−]
[src]
pub struct BookOptions { /* fields omitted */ }
Contains the options of a book.
Methods
impl BookOptions
[src]
fn new() -> BookOptions
Creates a new BookOptions struct from the default compliled string
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(&[]); // Set author book.options.set("author", "Joan Doe").unwrap(); // Set numbering to chapters and subsections book.options.set("rendering.num_depth", "2").unwrap(); // Try to set invalid key "autor" let result = book.options.set("autor", "John Smith"); assert!(result.is_err()); // error: "author" was mispelled "autor" let result = book.options.set("rendering.num_depth", "foo"); assert!(result.is_err()); // error: numbering must be an intRun
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 the correct path correction 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 get_f32(&self, key: &str) -> Result<f32>
gets a float 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