use std::fmt;
use super::Feed;
use super::atom::AtomFeed;
use super::rss2::Rss2Feed;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FeedParseError {
pub message: String,
}
impl FeedParseError {
pub(super) fn new(msg: impl Into<String>) -> Self {
Self {
message: msg.into(),
}
}
}
impl fmt::Display for FeedParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "feed parse error: {}", self.message)
}
}
impl std::error::Error for FeedParseError {}
#[derive(Debug, Clone, PartialEq)]
pub struct CollectError<F> {
pub error: FeedParseError,
pub partial: F,
}
impl<F: fmt::Debug> fmt::Display for CollectError<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "collect failed: {} (partial feed retained)", self.error)
}
}
impl<F: fmt::Debug> std::error::Error for CollectError<F> {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.error)
}
}
pub type Rss2CollectError = CollectError<Rss2Feed>;
pub type AtomCollectError = CollectError<AtomFeed>;
pub type FeedCollectError = CollectError<Feed>;