pub fn parse<'a, T: Parse<'a>>(buf: &'a ParseBuffer<'a>) -> Result<T>
Expand description
A top-level convenience parsing function that parses a T
from buf
and
requires that all tokens in buf
are consume.
This generic parsing function can be used to parse any T
implementing the
Parse
trait. It is not used from Parse
trait implementations.
ยงExamples
use wast::Wat;
use wast::parser::{self, ParseBuffer};
let wat = "(module (func))";
let buf = ParseBuffer::new(wat)?;
let module = parser::parse::<Wat>(&buf)?;
or parsing simply a fragment
use wast::parser::{self, ParseBuffer};
let wat = "12";
let buf = ParseBuffer::new(wat)?;
let val = parser::parse::<u32>(&buf)?;
assert_eq!(val, 12);