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
use quick_xml::de::from_str;
use crate::blog::Blog;
use self::{atom::AtomFeed, error::ParserError, rss::RssFeed, traits::WebFeed};
pub mod atom;
pub mod error;
pub mod rss;
mod traits;
pub fn parse_web_feed(xml: &str) -> Result<Blog, ParserError> {
from_str::<RssFeed>(xml).into_blog().or_else(|e1| {
from_str::<AtomFeed>(xml)
.into_blog()
.map_err(|e2| ParserError::Parse(format!("{e1}\n{e2}")))
})
}
fn limit_description(desc: &str, limit: usize) -> String {
let mut res = desc.chars().take(limit).collect::<String>();
if desc.chars().count() >= limit {
res += "...";
}
res
}