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]

[src]

Creates a new BookOptions struct from the default compiled string

[src]

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

[src]

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());

[src]

Get a stringvec option

[src]

Get a path option.

Adds the correct path correction before it.

[src]

Get a path option

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

[src]

Gets a bool option

Example

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

[src]

Gets a char option

[src]

Gets an int option

Example

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

[src]

Gets a float option

[src]

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]

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for BookOptions

impl Sync for BookOptions