{"id":394387,"date":"2024-06-29T11:35:10","date_gmt":"2024-06-29T11:35:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=394387"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=394387","title":{"rendered":"<span>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432 \u043d\u0430 Rust<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong><em>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/em><\/strong><\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435 \u043a\u043e\u0442\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043d \u0440\u0430\u0437\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0435\u0442 \u0441\u043b\u043e\u0432\u0430, \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0438\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a \u0438\u043d\u0442\u043e\u043d\u0430\u0446\u0438\u044f\u043c, \u0430 \u043f\u043e\u0442\u043e\u043c \u0440\u0435\u0448\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0451 \u044d\u0442\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u043b\u043e\u0436\u043d\u043e, \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u043e\u0432\u0438\u0442\u044c \u043c\u044b\u0448\u0435\u0439. <\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/858\/c23\/9f1\/858c239f1b8b6f08b0e43ff445809a7d.gif\" width=\"500\" height=\"365\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/858\/c23\/9f1\/858c239f1b8b6f08b0e43ff445809a7d.gif\"\/><\/figure>\n<p>\u041d\u043e \u0431\u043b\u0430\u0433\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441, \u043b\u044e\u0434\u0438\u0448\u0435\u043a, \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0437\u043b\u043e\u0436\u0438\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438. \u041a\u0430\u043a \u0440\u0430\u0437 \u043e\u0431 \u044d\u0442\u043e\u043c \u0438 \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c \u0432 \u043d\u0430\u0448\u0435\u0439 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u2014 \u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432 \u043d\u0430 Rust.<\/p>\n<p>\u0410 \u0438\u043c\u0435\u043d\u043d\u043e &#8212; \u043e \u0434\u0432\u0443\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <em>nom<\/em>.<\/p>\n<h2>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Nom<\/h2>\n<p>\u0412 <code>nom<\/code> \u043f\u0430\u0440\u0441\u0435\u0440\u044b \u0441\u0442\u0440\u043e\u044f\u0442\u0441\u044f \u0438\u0437 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432. <\/p>\n<p><code>nom<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u043e\u0432 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445:<\/p>\n<ol>\n<li>\n<p><code>tag<\/code> \u0438 <code>tag_no_case<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"rust\">use nom::bytes::complete::tag;  fn parse_hello(input: &amp;str) -> IResult&lt;&amp;str, &amp;str> {     tag(\"hello, habr\")(input) }<\/code><\/pre>\n<\/li>\n<li>\n<p><code>alt<\/code> \u2014 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432:<\/p>\n<pre><code class=\"rust\">use nom::branch::alt;  fn parse_bool(input: &amp;str) -> IResult&lt;&amp;str, bool> {     alt((value(true, tag(\"true\")), value(false, tag(\"false\"))))(input) }<\/code><\/pre>\n<\/li>\n<li>\n<p><code>many0<\/code> \u0438 <code>many1<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u0430:<\/p>\n<pre><code class=\"rust\">use nom::multi::many1; use nom::character::complete::digit1;  fn parse_digits(input: &amp;str) -> IResult&lt;&amp;str, Vec&lt;&amp;str>> {     many1(digit1)(input) }<\/code><\/pre>\n<\/li>\n<li>\n<p><code>map<\/code> \u0438 <code>map_res<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u0430\u0440\u0441\u0435\u0440\u0430:<\/p>\n<pre><code class=\"rust\">use nom::combinator::map_res; use std::str::FromStr;  fn parse_int(input: &amp;str) -> IResult&lt;&amp;str, i32> {     map_res(digit1, FromStr::from_str)(input) }<\/code><\/pre>\n<\/li>\n<li>\n<p><code>do_parse<\/code> \u0438 <code>tuple<\/code> \u2014 \u043c\u0430\u043a\u0440\u043e\u0441\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430:<\/p>\n<pre><code class=\"rust\">use nom::sequence::tuple;  fn parse_tuple(input: &amp;str) -> IResult&lt;&amp;str, (&amp;str, &amp;str)> {     tuple((alpha1, digit1))(input) }<\/code><\/pre>\n<\/li>\n<\/ol>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432<\/h4>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0440\u0441\u0435\u0440\u0430 \u0434\u043b\u044f RGB \u0446\u0432\u0435\u0442\u0430 \u0432 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<\/p>\n<pre><code class=\"rust\">use nom::bytes::complete::tag; use nom::character::complete::take_while_m_n; use nom::combinator::map_res; use nom::IResult;  fn is_hex_digit(c: char) -> bool {     c.is_digit(16) }  fn from_hex(input: &amp;str) -> Result&lt;u8, std::num::ParseIntError> {     u8::from_str_radix(input, 16) }  fn hex_primary(input: &amp;str) -> IResult&lt;&amp;str, u8> {     map_res(take_while_m_n(2, 2, is_hex_digit), from_hex)(input) }  #[derive(Debug, PartialEq)] struct Color {     red: u8,     green: u8,     blue: u8, }  fn hex_color(input: &amp;str) -> IResult&lt;&amp;str, Color> {     let (input, _) = tag(\"#\")(input)?;     let (input, (red, green, blue)) = (hex_primary, hex_primary, hex_primary).parse(input)?;     Ok((input, Color { red, green, blue })) }  fn main() {     println!(\"{:?}\", hex_color(\"#2F14DF\")); }  #[test] fn parse_color() {     assert_eq!(         hex_color(\"#2F14DF\"),         Ok((             \"\",             Color {                 red: 47,                 green: 20,                 blue: 223,             }         ))     ); }<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0441\u0435\u0440\u044b \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430, \u0447\u0442\u043e \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043f\u0430\u0440\u0441\u0435\u0440\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 \u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0430\u0440\u0441\u0435\u0440 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"rust\">use nom::character::complete::digit1; use nom::combinator::map_res; use nom::sequence::tuple; use nom::IResult; use std::str::FromStr;  fn parse_number(input: &amp;str) -> IResult&lt;&amp;str, i64> {     map_res(digit1, FromStr::from_str)(input) }  fn parse_term(input: &amp;str) -> IResult&lt;&amp;str, i64> {     parse_number(input) }  fn parse_expression(input: &amp;str) -> IResult&lt;&amp;str, i64> {     let (input, (left, _, right)) = tuple((parse_term, tag(\"+\"), parse_term))(input)?;     Ok((input, left + right)) }  fn main() {     println!(\"{:?}\", parse_expression(\"3+5\")); }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 <code>Peekable<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0431\u0435\u0437 \u0435\u0433\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f. \u041c\u0430\u0441\u0442\u0445\u0435\u0432 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432:<\/p>\n<pre><code class=\"rust\">use std::iter::Peekable; use std::str::Chars;  fn parse_term(iter: &amp;mut Peekable&lt;Chars>) -> Option&lt;i64> {     let mut number = 0;     while let Some(&amp;ch) = iter.peek() {         if ch.is_digit(10) {             number = number * 10 + ch.to_digit(10).unwrap() as i64;             iter.next();         } else {             break;         }     }     Some(number) }  fn main() {     let input = \"12345\";     let mut iter = input.chars().peekable();     let number = parse_term(&amp;mut iter);     println!(\"Parsed number: {:?}\", number); }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0440\u0441\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0425\u0430\u0431\u0440:  <\/p>\n<pre><code class=\"rust\">use nom::bytes::complete::{tag, take_until}; use nom::sequence::delimited; use nom::IResult; use reqwest;  async fn fetch_habr() -> Result&lt;String, reqwest::Error> {     let response = reqwest::get(\"https:\/\/habr.com\").await?;     let body = response.text().await?;     Ok(body) }  fn parse_title(input: &amp;str) -> IResult&lt;&amp;str, &amp;str> {     delimited(tag(\"&lt;a href=\\\"\/ru\/post\/\"), take_until(\"\\\">\"), take_until(\"&lt;\/a>\"))(input) }  fn parse_titles(input: &amp;str) -> Vec&lt;&amp;str> {     let mut titles = Vec::new();     let mut rest = input;      while let Ok((remaining, title)) = parse_title(rest) {         titles.push(title);         rest = remaining;     }      titles }  #[tokio::main] async fn main() {     match fetch_habr().await {         Ok(body) => {             let titles = parse_titles(&amp;body);             for title in titles {                 println!(\"Title: {}\", title);             }         }         Err(e) => eprintln!(\"Error fetching the page: {}\", e),     } }<\/code><\/pre>\n<ol>\n<li>\n<p><code>fetch_habr<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441 \u0425\u0430\u0431\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p><code>parse_title<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<\/li>\n<li>\n<p><code>parse_titles<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <a href=\"https:\/\/github.com\/rust-bakery\/nom\">\u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0437\u0434\u0435\u0441\u044c<\/a>. \u0410 \u043f\u043e\u043a\u0430 \u043c\u044b\u043f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 &#8212; <em>Chumsky<\/em>.<\/p>\n<h2>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Chumsky <\/h2>\n<p>Chumsky \u2014 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0433\u043e\u0434\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0435\u043a\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u043e\u0432 \u0432 \u044f\u0437\u044b\u043a\u0435 Rust. \u041e\u043d\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 API \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u0435\u0433\u043a\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c.<\/p>\n<p>Chumsky \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 <strong>\u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439<\/strong>, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0451 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e-\u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0435 \u044f\u0437\u044b\u043a\u0438.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432:<\/p>\n<ol>\n<li>\n<p><code>just<\/code> \u2014 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u0430\u0440\u0441\u0435\u0440 \u0434\u043b\u044f \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u0430:<\/p>\n<pre><code class=\"rust\">use chumsky::prelude::*;  let parser = just('a');<\/code><\/pre>\n<\/li>\n<li>\n<p><code>choice<\/code> \u2014 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432:<\/p>\n<pre><code class=\"rust\">let parser = choice((     just('a').to(1),     just('b').to(2), ));<\/code><\/pre>\n<\/li>\n<li>\n<p><code>repeated<\/code> \u2014 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u043f\u0430\u0440\u0441\u0435\u0440:<\/p>\n<pre><code class=\"rust\">let parser = just('a').repeated();<\/code><\/pre>\n<\/li>\n<li>\n<p><code>map<\/code> \u2014 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0430\u0440\u0441\u0435\u0440\u0430:<\/p>\n<pre><code class=\"rust\">let parser = just('a').map(|_| 42);<\/code><\/pre>\n<\/li>\n<li>\n<p><code>recursive<\/code> \u2014 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0441\u0435\u0440\u044b:<\/p>\n<pre><code class=\"rust\">let parser = recursive(|bf| choice((     just('&lt;').to(Instr::Left),     just('>').to(Instr::Right),     bf.delimited_by(just('['), just(']')).map(Instr::Loop), )).repeated());<\/code><\/pre>\n<\/li>\n<\/ol>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/h4>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438 \u0441\u043a\u043e\u0431\u043e\u043a:<\/p>\n<pre><code class=\"rust\">use chumsky::prelude::*; use chumsky::primitive::recursive;  #[derive(Debug, PartialEq)] enum Expr {     Num(i64),     Add(Box&lt;Expr>, Box&lt;Expr>),     Sub(Box&lt;Expr>, Box&lt;Expr>),     Mul(Box&lt;Expr>, Box&lt;Expr>),     Div(Box&lt;Expr>, Box&lt;Expr>), }  fn expr_parser() -> impl Parser&lt;char, Expr, Error = Simple&lt;char>> {     recursive(|expr| {         let num = text::int(10).from_str().unwrapped().map(Expr::Num);          let atom = num             .or(expr.delimited_by(just('('), just(')')));          let op = just('+').to(Expr::Add)             .or(just('-').to(Expr::Sub))             .or(just('*').to(Expr::Mul))             .or(just('\/').to(Expr::Div));          atom.clone().then(op.then(expr).repeated()).foldl(|lhs, (op, rhs)| op(Box::new(lhs), Box::new(rhs)))     }) }  fn main() {     let parser = expr_parser().then_ignore(end());      let expr = parser.parse(\"(1 + 2) * 3\").unwrap();     println!(\"{:?}\", expr); \/\/ Output: Mul(Add(Num(1), Num(2)), Num(3)) }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u0430 JSON \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b, \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u0443\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u0430\u0440\u0441\u0435\u0440\u044b \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 JSON-\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b:<\/p>\n<pre><code class=\"rust\">use chumsky::prelude::*; use chumsky::primitive::choice;  #[derive(Debug, PartialEq)] enum Json {     Null,     Bool(bool),     Number(f64),     String(String),     Array(Vec&lt;Json>),     Object(Vec&lt;(String, Json)>), }  fn json_parser() -> impl Parser&lt;char, Json, Error = Simple&lt;char>> {     let null = just(\"null\").to(Json::Null);     let boolean = choice((         just(\"true\").to(Json::Bool(true)),         just(\"false\").to(Json::Bool(false)),     ));     let number = text::int(10).chain::&lt;char, _, _>(just('.').chain(text::digits(10)).or_not())         .from_str().unwrapped().map(Json::Number);     let string = just('\"').ignore_then(text::take_until(just('\"'))).map(Json::String);     let array = json_parser().repeated().delimited_by(just('['), just(']')).map(Json::Array);     let pair = string.clone().then_ignore(just(':')).then(json_parser());     let object = pair.repeated().delimited_by(just('{'), just('}')).map(Json::Object);      choice((null, boolean, number, string, array, object)) }  fn main() {     let parser = json_parser().then_ignore(end());      let json = parser.parse(r#\"{\"key\": \"value\", \"array\": [null, true, 42.0]}\"#).unwrap();     println!(\"{:?}\", json); \/\/ Output: Object([(\"key\", String(\"value\")), (\"array\", Array([Null, Bool(true), Number(42.0)]))]) }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0440\u0441\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0425\u0430\u0431\u0440:  <\/p>\n<pre><code class=\"rust\">use chumsky::prelude::*; use chumsky::text::{text, TextParser}; use reqwest;  async fn fetch_habr() -> Result&lt;String, reqwest::Error> {     let response = reqwest::get(\"https:\/\/habr.com\").await?;     let body = response.text().await?;     Ok(body) }  fn parser() -> impl Parser&lt;char, Vec&lt;String>, Error = Simple&lt;char>> {     let title_start = text::text(\"&lt;a href=\\\"\/ru\/post\/\").ignored();     let title_end = text::text(\"\\\">\").ignored();     let title_parser = title_start         .clone()         .then(text::take_until(title_end.clone()))         .map(|((), title): ((), String)| title);      title_parser.repeated() }  #[tokio::main] async fn main() {     match fetch_habr().await {         Ok(body) => {             let parser = parser();             let titles = parser.parse(body.chars().collect::&lt;String>()).unwrap();             for title in titles {                 println!(\"Title: {}\", title);             }         }         Err(e) => eprintln!(\"Error fetching the page: {}\", e),     } }<\/code><\/pre>\n<hr\/>\n<ol>\n<li>\n<p><code>fetch_habr<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441 \u0425\u0430\u0431\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p><code>parser<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0441\u0442\u0430\u0442\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p><code>title_start<\/code> \u0438 <code>title_end<\/code> \u2014 \u043f\u0430\u0440\u0441\u0435\u0440\u044b \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0438 \u043a\u043e\u043d\u0446\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p><code>title_parser<\/code> \u2014 \u043f\u0430\u0440\u0441\u0435\u0440 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<\/li>\n<li>\n<p><code>repeated<\/code> \u2014 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f <code>title_parser<\/code>.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <a href=\"https:\/\/docs.rs\/chumsky\/latest\/chumsky\/\">\u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0437\u0434\u0435\u0441\u044c.<\/a><\/p>\n<p><em>\u0410 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u044f\u0437\u044b\u043a\u0430\u043c\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441\u043e\u0432 \u043e\u0442 \u043c\u043e\u0438\u0445 \u0434\u0440\u0443\u0437\u0435\u0439 \u0438\u0437 OTUS. <\/em><a href=\"https:\/\/otus.pw\/eWXx\/\"><em>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435<\/em><\/a><em>.<\/em><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/816687\/\"> https:\/\/habr.com\/ru\/articles\/816687\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong><em>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/em><\/strong><\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435 \u043a\u043e\u0442\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043d \u0440\u0430\u0437\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0435\u0442 \u0441\u043b\u043e\u0432\u0430, \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0438\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a \u0438\u043d\u0442\u043e\u043d\u0430\u0446\u0438\u044f\u043c, \u0430 \u043f\u043e\u0442\u043e\u043c \u0440\u0435\u0448\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0451 \u044d\u0442\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u043b\u043e\u0436\u043d\u043e, \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u043e\u0432\u0438\u0442\u044c \u043c\u044b\u0448\u0435\u0439. <\/p>\n<figure class=\"\"><\/figure>\n<p>\u041d\u043e \u0431\u043b\u0430\u0433\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441, \u043b\u044e\u0434\u0438\u0448\u0435\u043a, \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0437\u043b\u043e\u0436\u0438\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438. \u041a\u0430\u043a \u0440\u0430\u0437 \u043e\u0431 \u044d\u0442\u043e\u043c \u0438 \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c \u0432 \u043d\u0430\u0448\u0435\u0439 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u2014 \u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432 \u043d\u0430 Rust.<\/p>\n<p>\u0410 \u0438\u043c\u0435\u043d\u043d\u043e &#8212; \u043e \u0434\u0432\u0443\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <em>nom<\/em>.<\/p>\n<h2>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Nom<\/h2>\n<p>\u0412 <code>nom<\/code> \u043f\u0430\u0440\u0441\u0435\u0440\u044b \u0441\u0442\u0440\u043e\u044f\u0442\u0441\u044f \u0438\u0437 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432. <\/p>\n<p><code>nom<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u043e\u0432 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445:<\/p>\n<ol>\n<li>\n<p><code>tag<\/code> \u0438 <code>tag_no_case<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"rust\">use nom::bytes::complete::tag;  fn parse_hello(input: &amp;str) -> IResult&lt;&amp;str, &amp;str> {     tag(\"hello, habr\")(input) }<\/code><\/pre>\n<\/li>\n<li>\n<p><code>alt<\/code> \u2014 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432:<\/p>\n<pre><code class=\"rust\">use nom::branch::alt;  fn parse_bool(input: &amp;str) -> IResult&lt;&amp;str, bool> {     alt((value(true, tag(\"true\")), value(false, tag(\"false\"))))(input) }<\/code><\/pre>\n<\/li>\n<li>\n<p><code>many0<\/code> \u0438 <code>many1<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u0430:<\/p>\n<pre><code class=\"rust\">use nom::multi::many1; use nom::character::complete::digit1;  fn parse_digits(input: &amp;str) -> IResult&lt;&amp;str, Vec&lt;&amp;str>> {     many1(digit1)(input) }<\/code><\/pre>\n<\/li>\n<li>\n<p><code>map<\/code> \u0438 <code>map_res<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u0430\u0440\u0441\u0435\u0440\u0430:<\/p>\n<pre><code class=\"rust\">use nom::combinator::map_res; use std::str::FromStr;  fn parse_int(input: &amp;str) -> IResult&lt;&amp;str, i32> {     map_res(digit1, FromStr::from_str)(input) }<\/code><\/pre>\n<\/li>\n<li>\n<p><code>do_parse<\/code> \u0438 <code>tuple<\/code> \u2014 \u043c\u0430\u043a\u0440\u043e\u0441\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430:<\/p>\n<pre><code class=\"rust\">use nom::sequence::tuple;  fn parse_tuple(input: &amp;str) -> IResult&lt;&amp;str, (&amp;str, &amp;str)> {     tuple((alpha1, digit1))(input) }<\/code><\/pre>\n<\/li>\n<\/ol>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432<\/h4>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0440\u0441\u0435\u0440\u0430 \u0434\u043b\u044f RGB \u0446\u0432\u0435\u0442\u0430 \u0432 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<\/p>\n<pre><code class=\"rust\">use nom::bytes::complete::tag; use nom::character::complete::take_while_m_n; use nom::combinator::map_res; use nom::IResult;  fn is_hex_digit(c: char) -> bool {     c.is_digit(16) }  fn from_hex(input: &amp;str) -> Result&lt;u8, std::num::ParseIntError> {     u8::from_str_radix(input, 16) }  fn hex_primary(input: &amp;str) -> IResult&lt;&amp;str, u8> {     map_res(take_while_m_n(2, 2, is_hex_digit), from_hex)(input) }  #[derive(Debug, PartialEq)] struct Color {     red: u8,     green: u8,     blue: u8, }  fn hex_color(input: &amp;str) -> IResult&lt;&amp;str, Color> {     let (input, _) = tag(\"#\")(input)?;     let (input, (red, green, blue)) = (hex_primary, hex_primary, hex_primary).parse(input)?;     Ok((input, Color { red, green, blue })) }  fn main() {     println!(\"{:?}\", hex_color(\"#2F14DF\")); }  #[test] fn parse_color() {     assert_eq!(         hex_color(\"#2F14DF\"),         Ok((             \"\",             Color {                 red: 47,                 green: 20,                 blue: 223,             }         ))     ); }<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0441\u0435\u0440\u044b \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430, \u0447\u0442\u043e \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043f\u0430\u0440\u0441\u0435\u0440\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 \u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0430\u0440\u0441\u0435\u0440 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"rust\">use nom::character::complete::digit1; use nom::combinator::map_res; use nom::sequence::tuple; use nom::IResult; use std::str::FromStr;  fn parse_number(input: &amp;str) -> IResult&lt;&amp;str, i64> {     map_res(digit1, FromStr::from_str)(input) }  fn parse_term(input: &amp;str) -> IResult&lt;&amp;str, i64> {     parse_number(input) }  fn parse_expression(input: &amp;str) -> IResult&lt;&amp;str, i64> {     let (input, (left, _, right)) = tuple((parse_term, tag(\"+\"), parse_term))(input)?;     Ok((input, left + right)) }  fn main() {     println!(\"{:?}\", parse_expression(\"3+5\")); }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 <code>Peekable<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0431\u0435\u0437 \u0435\u0433\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f. \u041c\u0430\u0441\u0442\u0445\u0435\u0432 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432:<\/p>\n<pre><code class=\"rust\">use std::iter::Peekable; use std::str::Chars;  fn parse_term(iter: &amp;mut Peekable&lt;Chars>) -> Option&lt;i64> {     let mut number = 0;     while let Some(&amp;ch) = iter.peek() {         if ch.is_digit(10) {             number = number * 10 + ch.to_digit(10).unwrap() as i64;             iter.next();         } else {             break;         }     }     Some(number) }  fn main() {     let input = \"12345\";     let mut iter = input.chars().peekable();     let number = parse_term(&amp;mut iter);     println!(\"Parsed number: {:?}\", number); }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0440\u0441\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0425\u0430\u0431\u0440:  <\/p>\n<pre><code class=\"rust\">use nom::bytes::complete::{tag, take_until}; use nom::sequence::delimited; use nom::IResult; use reqwest;  async fn fetch_habr() -> Result&lt;String, reqwest::Error> {     let response = reqwest::get(\"https:\/\/habr.com\").await?;     let body = response.text().await?;     Ok(body) }  fn parse_title(input: &amp;str) -> IResult&lt;&amp;str, &amp;str> {     delimited(tag(\"&lt;a href=\\\"\/ru\/post\/\"), take_until(\"\\\">\"), take_until(\"&lt;\/a>\"))(input) }  fn parse_titles(input: &amp;str) -> Vec&lt;&amp;str> {     let mut titles = Vec::new();     let mut rest = input;      while let Ok((remaining, title)) = parse_title(rest) {         titles.push(title);         rest = remaining;     }      titles }  #[tokio::main] async fn main() {     match fetch_habr().await {         Ok(body) => {             let titles = parse_titles(&amp;body);             for title in titles {                 println!(\"Title: {}\", title);             }         }         Err(e) => eprintln!(\"Error fetching the page: {}\", e),     } }<\/code><\/pre>\n<ol>\n<li>\n<p><code>fetch_habr<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441 \u0425\u0430\u0431\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p><code>parse_title<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<\/li>\n<li>\n<p><code>parse_titles<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <a href=\"https:\/\/github.com\/rust-bakery\/nom\">\u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0437\u0434\u0435\u0441\u044c<\/a>. \u0410 \u043f\u043e\u043a\u0430 \u043c\u044b\u043f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 &#8212; <em>Chumsky<\/em>.<\/p>\n<h2>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Chumsky <\/h2>\n<p>Chumsky \u2014 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0433\u043e\u0434\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0435\u043a\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u043e\u0432 \u0432 \u044f\u0437\u044b\u043a\u0435 Rust. \u041e\u043d\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 API \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u0435\u0433\u043a\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c.<\/p>\n<p>Chumsky \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 <strong>\u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439<\/strong>, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0451 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e-\u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0435 \u044f\u0437\u044b\u043a\u0438.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432:<\/p>\n<ol>\n<li>\n<p><code>just<\/code> \u2014 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u0430\u0440\u0441\u0435\u0440 \u0434\u043b\u044f \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u0430:<\/p>\n<pre><code class=\"rust\">use chumsky::prelude::*;  let parser = just('a');<\/code><\/pre>\n<\/li>\n<li>\n<p><code>choice<\/code> \u2014 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432:<\/p>\n<pre><code class=\"rust\">let parser = choice((     just('a').to(1),     just('b').to(2), ));<\/code><\/pre>\n<\/li>\n<li>\n<p><code>repeated<\/code> \u2014 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u043f\u0430\u0440\u0441\u0435\u0440:<\/p>\n<pre><code class=\"rust\">let parser = just('a').repeated();<\/code><\/pre>\n<\/li>\n<li>\n<p><code>map<\/code> \u2014 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0430\u0440\u0441\u0435\u0440\u0430:<\/p>\n<pre><code class=\"rust\">let parser = just('a').map(|_| 42);<\/code><\/pre>\n<\/li>\n<li>\n<p><code>recursive<\/code> \u2014 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0441\u0435\u0440\u044b:<\/p>\n<pre><code class=\"rust\">let parser = recursive(|bf| choice((     just('&lt;').to(Instr::Left),     just('>').to(Instr::Right),     bf.delimited_by(just('['), just(']')).map(Instr::Loop), )).repeated());<\/code><\/pre>\n<\/li>\n<\/ol>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/h4>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438 \u0441\u043a\u043e\u0431\u043e\u043a:<\/p>\n<pre><code class=\"rust\">use chumsky::prelude::*; use chumsky::primitive::recursive;  #[derive(Debug, PartialEq)] enum Expr {     Num(i64),     Add(Box&lt;Expr>, Box&lt;Expr>),     Sub(Box&lt;Expr>, Box&lt;Expr>),     Mul(Box&lt;Expr>, Box&lt;Expr>),     Div(Box&lt;Expr>, Box&lt;Expr>), }  fn expr_parser() -> impl Parser&lt;char, Expr, Error = Simple&lt;char>> {     recursive(|expr| {         let num = text::int(10).from_str().unwrapped().map(Expr::Num);          let atom = num             .or(expr.delimited_by(just('('), just(')')));          let op = just('+').to(Expr::Add)             .or(just('-').to(Expr::Sub))             .or(just('*').to(Expr::Mul))             .or(just('\/').to(Expr::Div));          atom.clone().then(op.then(expr).repeated()).foldl(|lhs, (op, rhs)| op(Box::new(lhs), Box::new(rhs)))     }) }  fn main() {     let parser = expr_parser().then_ignore(end());      let expr = parser.parse(\"(1 + 2) * 3\").unwrap();     println!(\"{:?}\", expr); \/\/ Output: Mul(Add(Num(1), Num(2)), Num(3)) }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u0430 JSON \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b, \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u0443\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u0430\u0440\u0441\u0435\u0440\u044b \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 JSON-\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b:<\/p>\n<pre><code class=\"rust\">use chumsky::prelude::*; use chumsky::primitive::choice;  #[derive(Debug, PartialEq)] enum Json {     Null,     Bool(bool),     Number(f64),     String(String),     Array(Vec&lt;Json>),     Object(Vec&lt;(String, Json)>), }  fn json_parser() -> impl Parser&lt;char, Json, Error = Simple&lt;char>> {     let null = just(\"null\").to(Json::Null);     let boolean = choice((         just(\"true\").to(Json::Bool(true)),         just(\"false\").to(Json::Bool(false)),     ));     let number = text::int(10).chain::&lt;char, _, _>(just('.').chain(text::digits(10)).or_not())         .from_str().unwrapped().map(Json::Number);     let string = just('\"').ignore_then(text::take_until(just('\"'))).map(Json::String);     let array = json_parser().repeated().delimited_by(just('['), just(']')).map(Json::Array);     let pair = string.clone().then_ignore(just(':')).then(json_parser());     let object = pair.repeated().delimited_by(just('{'), just('}')).map(Json::Object);      choice((null, boolean, number, string, array, object)) }  fn main() {     let parser = json_parser().then_ignore(end());      let json = parser.parse(r#\"{\"key\": \"value\", \"array\": [null, true, 42.0]}\"#).unwrap();     println!(\"{:?}\", json); \/\/ Output: Object([(\"key\", String(\"value\")), (\"array\", Array([Null, Bool(true), Number(42.0)]))]) }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0440\u0441\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0425\u0430\u0431\u0440:  <\/p>\n<pre><code class=\"rust\">use chumsky::prelude::*; use chumsky::text::{text, TextParser}; use reqwest;  async fn fetch_habr() -> Result&lt;String, reqwest::Error> {     let response = reqwest::get(\"https:\/\/habr.com\").await?;     let body = response.text().await?;     Ok(body) }  fn parser() -> impl Parser&lt;char, Vec&lt;String>, Error = Simple&lt;char>> {     let title_start = text::text(\"&lt;a href=\\\"\/ru\/post\/\").ignored();     let title_end = text::text(\"\\\">\").ignored();     let title_parser = title_start         .clone()         .then(text::take_until(title_end.clone()))         .map(|((), title): ((), String)| title);      title_parser.repeated() }  #[tokio::main]<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-394387","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/394387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=394387"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/394387\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=394387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=394387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=394387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}