pub struct Parser<'input> { /* private fields */ }Expand description
Type-based parser for AsciiDoc content.
Parser provides a more discoverable, fluent API for parsing AsciiDoc documents.
§Examples
Basic usage:
use acdc_parser::Parser;
let content = "= Document Title\n\nParagraph text.";
let doc = Parser::new(content).parse()?;With options:
use acdc_parser::{Parser, Options, SafeMode};
let content = "= Document Title\n\nParagraph text.";
let options = Options::builder()
.with_safe_mode(SafeMode::Safe)
.with_timings()
.build();
let doc = Parser::new(content)
.with_options(options)
.parse()?;For file-based parsing, read the file first:
use acdc_parser::Parser;
use std::fs;
let content = fs::read_to_string("document.adoc")?;
let doc = Parser::new(&content).parse()?;Implementations§
Source§impl<'input> Parser<'input>
impl<'input> Parser<'input>
Sourcepub fn new(input: &'input str) -> Self
pub fn new(input: &'input str) -> Self
Create a new parser for the given input string.
The parser will use default options. Use with_options to customize.
§Example
use acdc_parser::Parser;
let parser = Parser::new("= Title\n\nContent");
let doc = parser.parse()?;Sourcepub fn with_options(self, options: Options) -> Self
pub fn with_options(self, options: Options) -> Self
Set the options for this parser.
This consumes the parser and returns a new one with the specified options.
§Example
use acdc_parser::{Parser, Options, SafeMode};
let options = Options::builder()
.with_safe_mode(SafeMode::Safe)
.build();
let parser = Parser::new("= Title")
.with_options(options);Sourcepub fn parse_inline(self) -> Result<Vec<InlineNode>, Error>
pub fn parse_inline(self) -> Result<Vec<InlineNode>, Error>
Parse only inline elements from the input.
This is useful for parsing fragments of AsciiDoc that contain only
inline markup like bold, italic, links, etc.
§Example
use acdc_parser::Parser;
let inlines = Parser::new("This is *bold* text").parse_inline()?;§Errors
Returns an error if the input cannot be parsed.
Trait Implementations§
Auto Trait Implementations§
impl<'input> Freeze for Parser<'input>
impl<'input> RefUnwindSafe for Parser<'input>
impl<'input> Send for Parser<'input>
impl<'input> Sync for Parser<'input>
impl<'input> Unpin for Parser<'input>
impl<'input> UnwindSafe for Parser<'input>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more