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
}