use std::error::Error; use std::fmt::{Display, Formatter}; use std::io; #[derive(Debug)] pub enum LoadErr { CantReadFile, Invalid, BufferTooShort, IO(io::Error), } impl From for LoadErr { fn from(err: io::Error) -> Self { if err.kind() == io::ErrorKind::UnexpectedEof { Self::BufferTooShort } else { Self::IO(err) } } } impl Display for LoadErr { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{self:?}") } } impl Error for LoadErr {} // This should be a different enum per part of file. Either return a list of these or take a callback // TODO: https://users.rust-lang.org/t/validation-monad/117894/6 // // load was partially successful. These are the defects that are in the now loaded project // #[derive(Debug, Clone, Copy)] // #[non_exhaustive] // pub enum LoadDefect { // /// deletes the effect // UnknownEffect, // /// replaced with empty text // InvalidText, // /// tries to replace with a sane default value // OutOfBoundsValue, // /// skips loading of the pointed to value // OutOfBoundsPtr, // }