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 Self::EmptyData => write!(f, "data series is empty"),
34 Self::UnknownColumn(name) => write!(f, "unknown column: {name}"),
35 Self::Io(err) => write!(f, "I/O error: {err}"),
36 Self::UnsupportedFormat(fmt_str) => write!(f, "unsupported format: {fmt_str}"),
37 Self::FontLoad(msg) => write!(f, "font loading error: {msg}"),
38 }
39 }
40}
41
42impl std::error::Error for PlotError {
43 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
44 match self {
45 Self::Io(err) => Some(err),
46 _ => None,
47 }
48 }
49}
50
51impl From<std::io::Error> for PlotError {
52 fn from(err: std::io::Error) -> Self {
53 Self::Io(err)
54 }
55}
56
57pub type Result<T> = std::result::Result<T, PlotError>;