1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! This module contains various parsers used in the feed-parser library.
//!
//! The parsers module provides functionality to parse different types of
//! feed formats, such as RSS and Atom. Each parser is responsible for
//! handling the specific details of its respective feed format, ensuring
//! that the feed data is correctly interpreted and converted into a
//! standardized format for further processing.
//!
//! # Quick Start
//!
//! ```
//! use feed_parser::parsers::{Feed, rss2};
//!
//! let rss_data = r#"
//! <rss version="2.0">
//! <channel>
//! <title>RSS Title</title>
//! <link>http://www.example.com/main.html</link>
//! <description>This is an example of an RSS feed</description>
//! <item>
//! <title>Item 1</title>
//! <link>http://www.example.com/item1.html</link>
//! <description>Item 1 description</description>
//! <pubDate>2024-01-01T23:59:02Z</pubDate>
//! </item>
//! </channel>
//! </rss>
//! "#;
//! let feeds: Vec<Feed> = rss2::parse(rss_data).unwrap();
//! assert_eq!(feeds[0].title, "Item 1");
//! assert_eq!(feeds[0].link, "http://www.example.com/item1.html");
//! assert_eq!(feeds[0].description.clone().unwrap(), "Item 1 description");
//! ```
//!
//! # Modules
//!
//! - `rss1`: Contains the RSS1.0 parser implementation.
//! - `rss2`: Contains the RSS2.0 parser implementation.
//! - `atom`: Contains the Atom parser implementation.
//!
//! # Errors
//!
//! Every parser returns [`ParseResult`], so malformed input is reported rather
//! than panicking. [`ParseError`] distinguishes ill-formed XML, entries that are
//! missing a required field, and documents that end inside an open entry.
//!
//! ```
//! use feed_parser::parsers::{errors::ParseError, rss2};
//!
//! // An <item> with no <title> cannot become a `Feed`.
//! let rss_data = r#"
//! <rss version="2.0">
//! <channel>
//! <item><description>no title here</description></item>
//! </channel>
//! </rss>
//! "#;
//! match rss2::parse(rss_data) {
//! Err(ParseError::MissingField(field)) => assert_eq!(field, "title"),
//! other => panic!("expected a MissingField error, got {other:?}"),
//! }
//! ```
//!
//! [`ParseError`]: crate::parsers::errors::ParseError
//! [`ParseResult`]: crate::parsers::errors::ParseResult