pub struct Parser<'a> { /* private fields */ }Implementations§
Source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
Sourcepub const fn new(input: &'a str) -> Self
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}Sourcepub fn parse(&mut self) -> Struct
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}Sourcepub fn errors(&self) -> &[ParseError]
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> 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