1use std::fmt;
4
5#[derive(Debug)]
7#[non_exhaustive]
8pub enum PlotError {
9 SeriesLengthMismatch {
11 expected: usize,
13 got: usize,
15 },
16 EmptyData,
18 UnknownColumn(String),
20 Io(std::io::Error),
22 UnsupportedFormat(String),
24 FontLoad(String),
26}
27
28impl fmt::Display for PlotError {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match self {
31 Self::SeriesLengthMismatch { expected, got } => {
32 write!(f, "series length mismatch: expected {expected}, got {got}")
33 }
34 Self::EmptyData => write!(f, "data series is empty"),
35 Self::UnknownColumn(name) => write!(f, "unknown column: {name}"),
36 Self::Io(err) => write!(f, "I/O error: {err}"),
37 Self::UnsupportedFormat(fmt_str) => write!(f, "unsupported format: {fmt_str}"),
38 Self::FontLoad(msg) => write!(f, "font loading error: {msg}"),
39 }
40 }
41}
42
43impl std::error::Error for PlotError {
44 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
45 match self {
46 Self::Io(err) => Some(err),
47 _ => None,
48 }
49 }
50}
51
52impl From<std::io::Error> for PlotError {
53 fn from(err: std::io::Error) -> Self {
54 Self::Io(err)
55 }
56}
57
58pub type Result<T> = std::result::Result<T, PlotError>;