feed-parser 2.0.0

A simple RSS 1.0 / RSS 2.0 / Atom feed parser
Documentation
use thiserror::Error;

/// Errors that can occur while parsing a feed.
///
/// This enum is `#[non_exhaustive]`: new variants may be added in future minor
/// releases, so downstream `match` expressions must include a wildcard arm.
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum ParseError {
    /// The input is not well-formed XML.
    #[error("Failed to parse XML: {0}")]
    XmlParseError(#[from] quick_xml::Error),

    /// An entry was well-formed XML but could not be turned into a [`Feed`].
    ///
    /// [`Feed`]: crate::parsers::Feed
    #[error("Failed to deserialize feed entry: {0}")]
    DeserializeError(#[from] quick_xml::DeError),

    /// The input contained a byte sequence that is not valid UTF-8.
    #[error("Feed contains invalid UTF-8: {0}")]
    Utf8Error(#[from] std::str::Utf8Error),

    /// Writing the normalized intermediate XML failed.
    #[error("Failed to write intermediate XML: {0}")]
    IoError(#[from] std::io::Error),

    /// The document is valid XML but not a valid feed (e.g. an unclosed entry).
    #[error("Invalid feed format: {0}")]
    InvalidFeedFormat(String),

    /// An entry is missing a field that [`Feed`] requires.
    ///
    /// [`Feed`]: crate::parsers::Feed
    #[error("Missing required field: {0}")]
    MissingField(String),
}

/// A [`Result`] alias whose error type is [`ParseError`].
pub type ParseResult<T> = Result<T, ParseError>;