1use std::{fmt, io};
2
3#[derive(Debug)]
5pub enum PickerError {
6 Io(io::Error),
8 Empty,
10 NoEnabledItems,
12 Cancelled,
15}
16
17impl fmt::Display for PickerError {
18 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19 match self {
20 Self::Io(source) => write!(f, "I/O error: {source}"),
21 Self::Empty => f.write_str("picker has no items"),
22 Self::NoEnabledItems => f.write_str("picker has no enabled items"),
23 Self::Cancelled => f.write_str("picker cancelled"),
24 }
25 }
26}
27impl std::error::Error for PickerError {
28 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
29 match self {
30 Self::Io(source) => Some(source),
31 Self::Empty | Self::NoEnabledItems | Self::Cancelled => None,
32 }
33 }
34}
35
36impl From<io::Error> for PickerError {
37 fn from(source: io::Error) -> Self {
38 Self::Io(source)
39 }
40}