• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! # Chapter 0: Introduction
2 //!
3 //! This tutorial assumes that you are:
4 //! - Already familiar with Rust
5 //! - Using `winnow` for the first time
6 //!
7 //! The focus will be on parsing in-memory strings (`&str`). Once done, you might want to check the
8 //! [Special Topics][_topic] for more specialized topics or examples.
9 //!
10 //! ## About
11 //!
12 //! `winnow` is a parser-combinator library. In other words, it gives you tools to define:
13 //! - "parsers", or functions that take an input and give back an output
14 //! - "combinators", or functions that take parsers and _combine_ them together!
15 //!
16 //! While "combinator" might be an unfamiliar word, you are likely using them in your rust code
17 //! today, like with the [`Iterator`] trait:
18 //! ```rust
19 //! let data = vec![1, 2, 3, 4, 5];
20 //! let even_count = data.iter()
21 //!     .copied()  // combinator
22 //!     .filter(|d| d % 2 == 0)  // combinator
23 //!     .count();  // combinator
24 //! ```
25 //!
26 //! Parser combinators are great because:
27 //!
28 //! - The parsers are small and easy to write
29 //! - The parsers components are easy to reuse (if they're general enough, please add them to winnow!)
30 //! - The parsers components are easy to test separately (unit tests and property-based tests)
31 //! - The parser combination code looks close to the grammar you would have written
32 //! - You can build partial parsers, specific to the data you need at the moment, and ignore the rest
33 
34 #![allow(unused_imports)]
35 use crate::_topic;
36 use std::iter::Iterator;
37 
38 pub use super::chapter_1 as next;
39 pub use crate::_tutorial as table_of_contents;
40