1use quick_xml::de::from_str;
5
6use crate::blog::Blog;
7
8use self::{atom::AtomFeed, error::ParserError, rss::RssFeed, traits::WebFeed};
9
10pub mod atom;
11pub mod error;
12pub mod rss;
13mod traits;
14
15pub fn parse_web_feed(xml: &str) -> Result<Blog, ParserError> {
21 from_str::<RssFeed>(xml).into_blog().or_else(|e1| {
22 from_str::<AtomFeed>(xml)
23 .into_blog()
24 .map_err(|e2| ParserError::Parse(format!("{e1}\n{e2}")))
25 })
26}
27
28fn limit_description(desc: &str, limit: usize) -> String {
31 let mut res = desc.chars().take(limit).collect::<String>();
32
33 if desc.chars().count() >= limit {
34 res += "...";
35 }
36
37 res
38}