Skip to main content

rusty_pv/
error.rs

1//! Public error type for the rusty-pv library API (FR-047, FR-057).
2
3/// Error type returned by [`Pv`](crate::Pv) operations.
4///
5/// `#[non_exhaustive]` allows additive variants in SemVer-minor releases per
6/// FR-057. Downstream code MUST use a wildcard `_` arm when matching.
7#[non_exhaustive]
8#[derive(Debug, thiserror::Error)]
9pub enum PvError {
10    /// I/O failure during a read or write operation.
11    #[error("rusty-pv: I/O error: {source}")]
12    Io {
13        /// Underlying `std::io::Error`.
14        #[source]
15        source: std::io::Error,
16    },
17
18    /// Rate-limit value was invalid (could not be parsed or is non-positive).
19    #[error("rusty-pv: invalid rate limit value: '{value}'")]
20    RateLimitInvalid {
21        /// The offending input value.
22        value: String,
23    },
24
25    /// Size hint value was invalid (could not be parsed or is non-positive).
26    #[error("rusty-pv: invalid size value: '{value}'")]
27    SizeInvalid {
28        /// The offending input value.
29        value: String,
30    },
31}
32
33impl From<std::io::Error> for PvError {
34    fn from(source: std::io::Error) -> Self {
35        PvError::Io { source }
36    }
37}