Struct crowbook::BookOptions [] [src]

pub struct BookOptions { /* fields omitted */ }

Contains the options of a book.

This structure offers some facilities to check the content of an option. It also verifies, when setting an option, that it corresponds to certain values (e.g. if you expect an int, you can't set this option to "foo").

Example

use crowbook::BookOptions;
let mut options = BookOptions::new();

// By default, `lang` is set to "en"
assert_eq!(options.get_str("lang").unwrap(), "en");

// We can change it to "fr"
options.set("lang", "fr").unwrap();
assert_eq!(options.get_str("lang").unwrap(), "fr");

// `epub.version` must be an int, we can't set it to a string
let res = options.set("epub.version", "foo");
assert!(res.is_err());

Methods

impl BookOptions
[src]

Creates a new BookOptions struct from the default compiled string

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 int

Gets a string option.

Returns

  • A string if key is valid and corresponds to a string
  • An error either if key is not valid or is not a string.

Example

use crowbook::BookOptions;
let options = BookOptions::new();
assert!(options.get_str("author").is_ok());
assert!(options.get_str("rendering.inline_toc").is_err());

Get a stringvec option

Get a path option.

Adds the correct path correction before it.

Get a path option

Don't add book's root path before it.

Gets a bool option

Example

let options = BookOptions::new();
assert!(options.get_bool("epub.toc.extras").is_ok());

Gets a char option

Gets an int option

Example

let options = BookOptions::new();
assert!(options.get_i32("rendering.num_depth").is_ok());

Gets a float option

Returns a description of all options valid to pass to a book.

Arguments

  • md: whether the output should be formatted in Markdown

Example

use crowbook::BookOptions;
println!("{}", BookOptions::description(false));

Trait Implementations

impl Debug for BookOptions
[src]

Formats the value using the given formatter.