Visitor

Trait Visitor 

Source
pub trait Visitor {
    // Required methods
    fn begin(&mut self, region: &Region) -> Result<(), Error>;
    fn end(&mut self, region: &Region) -> Result<(), Error>;
    fn text(&mut self, text: &str) -> Result<(), Error>;
    fn line_break(&mut self) -> Result<(), Error>;
    fn code(&mut self, text: &str) -> Result<(), Error>;

    // Provided methods
    fn with_visited_str(self, s: &str) -> Result<Self, Error>
       where Self: Sized { ... }
    fn with_parsed_str(self, parser: &Parser, s: &str) -> Result<Self, Error>
       where Self: Sized { ... }
}

Required Methods§

Source

fn begin(&mut self, region: &Region) -> Result<(), Error>

Source

fn end(&mut self, region: &Region) -> Result<(), Error>

Source

fn text(&mut self, text: &str) -> Result<(), Error>

Source

fn line_break(&mut self) -> Result<(), Error>

Source

fn code(&mut self, text: &str) -> Result<(), Error>

Provided Methods§

Source

fn with_visited_str(self, s: &str) -> Result<Self, Error>
where Self: Sized,

Visit a Matthewdown string.

§Arguments
  • s - The string of Matthewdown to visit.
§Example
use matthewdown::Visitor;
let result = matthewdown::HtmlVisitor::new()
    .with_visited_str(r#"
      1. Bullet 1
      2. Bullet 2
    "#)
    .unwrap()
    .into_output();

assert_eq!(result, "<ol><li>Bullet 1</li><li>Bullet 2</li></ol>");
Source

fn with_parsed_str(self, parser: &Parser, s: &str) -> Result<Self, Error>
where Self: Sized,

Visit a Matthewdown string using a particular parser.

§Arguments
  • parser - The parser to use.
  • s - The string of Matthewdown to visit.
§Example
// Make a normal parser...
let good_parser = matthewdown::Parser::default();
// Make a parser that doesn't understand any parsing rules...
let bad_parser  = matthewdown::Parser::blank();

use matthewdown::Visitor;
// Using the good parser works
assert!(matthewdown::HtmlVisitor::new()
    .with_parsed_str(&good_parser, "Hello!")
    .is_ok());

// Using the bad parser doesn't
assert!(matthewdown::HtmlVisitor::new()
    .with_parsed_str(&bad_parser, "Hello!")
    .is_err());

Implementors§

Source§

impl Visitor for NullVisitor

Source§

impl<'a> Visitor for SizedDyn<'a>

Source§

impl<F> Visitor for HtmlVisitor<F>
where F: HtmlWrite,

Source§

impl<F> Visitor for TextVisitor<F>
where F: Write,

Source§

impl<V> Visitor for MetadataVisitor<V>
where V: Visitor,