Skip to main content

Parser

Struct Parser 

Source
pub struct Parser<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Parser<'a>

Source

pub const fn new(input: &'a str) -> Self

Create a new parser over the input string.

Examples found in repository?
examples/benchmark.rs (line 45)
3fn main() {
4    let data = r#"
5# Config file
6server {
7    host "localhost"
8    port 8080
9    ssl true
10    threads 4
11}
12
13database {
14    connection "postgresql://localhost/mydb"
15    pool_size 10
16    timeout 30.5
17}
18
19users [
20    {
21        name "Alice"
22        age 30
23        roles ["admin" user]
24    }
25    {
26        name "Bob"
27        age 25
28        roles ["user"]
29    }
30]
31
32coordinates [
33    (100 200)
34    (300 400)
35    (500 600)
36]
37
38status :active
39mode :fullscreen
40color :rgb(255 128 0)
41"#;
42
43    // Warmup
44    for _ in 0..100 {
45        let mut parser = Parser::new(data);
46        let _ = parser.parse();
47    }
48
49    // Benchmark
50    let iterations = 200_000;
51    let start = std::time::Instant::now();
52
53    for _ in 0..iterations {
54        let mut parser = Parser::new(data);
55        let _ = parser.parse();
56        assert!(
57            parser.errors().is_empty(),
58            "benchmark should not contain errors"
59        );
60    }
61
62    let elapsed = start.elapsed();
63    let per_iter = elapsed / iterations;
64
65    println!("Parsed {} iterations in {:?}", iterations, elapsed);
66    println!("Average time per parse: {:?}", per_iter);
67    println!("Parses per second: {:.0}", 1.0 / per_iter.as_secs_f64());
68}
Source

pub fn parse(&mut self) -> Struct

Examples found in repository?
examples/benchmark.rs (line 46)
3fn main() {
4    let data = r#"
5# Config file
6server {
7    host "localhost"
8    port 8080
9    ssl true
10    threads 4
11}
12
13database {
14    connection "postgresql://localhost/mydb"
15    pool_size 10
16    timeout 30.5
17}
18
19users [
20    {
21        name "Alice"
22        age 30
23        roles ["admin" user]
24    }
25    {
26        name "Bob"
27        age 25
28        roles ["user"]
29    }
30]
31
32coordinates [
33    (100 200)
34    (300 400)
35    (500 600)
36]
37
38status :active
39mode :fullscreen
40color :rgb(255 128 0)
41"#;
42
43    // Warmup
44    for _ in 0..100 {
45        let mut parser = Parser::new(data);
46        let _ = parser.parse();
47    }
48
49    // Benchmark
50    let iterations = 200_000;
51    let start = std::time::Instant::now();
52
53    for _ in 0..iterations {
54        let mut parser = Parser::new(data);
55        let _ = parser.parse();
56        assert!(
57            parser.errors().is_empty(),
58            "benchmark should not contain errors"
59        );
60    }
61
62    let elapsed = start.elapsed();
63    let per_iter = elapsed / iterations;
64
65    println!("Parsed {} iterations in {:?}", iterations, elapsed);
66    println!("Average time per parse: {:?}", per_iter);
67    println!("Parses per second: {:.0}", 1.0 / per_iter.as_secs_f64());
68}
Source

pub fn errors(&self) -> &[ParseError]

Examples found in repository?
examples/benchmark.rs (line 57)
3fn main() {
4    let data = r#"
5# Config file
6server {
7    host "localhost"
8    port 8080
9    ssl true
10    threads 4
11}
12
13database {
14    connection "postgresql://localhost/mydb"
15    pool_size 10
16    timeout 30.5
17}
18
19users [
20    {
21        name "Alice"
22        age 30
23        roles ["admin" user]
24    }
25    {
26        name "Bob"
27        age 25
28        roles ["user"]
29    }
30]
31
32coordinates [
33    (100 200)
34    (300 400)
35    (500 600)
36]
37
38status :active
39mode :fullscreen
40color :rgb(255 128 0)
41"#;
42
43    // Warmup
44    for _ in 0..100 {
45        let mut parser = Parser::new(data);
46        let _ = parser.parse();
47    }
48
49    // Benchmark
50    let iterations = 200_000;
51    let start = std::time::Instant::now();
52
53    for _ in 0..iterations {
54        let mut parser = Parser::new(data);
55        let _ = parser.parse();
56        assert!(
57            parser.errors().is_empty(),
58            "benchmark should not contain errors"
59        );
60    }
61
62    let elapsed = start.elapsed();
63    let per_iter = elapsed / iterations;
64
65    println!("Parsed {} iterations in {:?}", iterations, elapsed);
66    println!("Average time per parse: {:?}", per_iter);
67    println!("Parses per second: {:.0}", 1.0 / per_iter.as_secs_f64());
68}

Auto Trait Implementations§

§

impl<'a> Freeze for Parser<'a>

§

impl<'a> RefUnwindSafe for Parser<'a>

§

impl<'a> Send for Parser<'a>

§

impl<'a> Sync for Parser<'a>

§

impl<'a> Unpin for Parser<'a>

§

impl<'a> UnsafeUnpin for Parser<'a>

§

impl<'a> UnwindSafe for Parser<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.