old school music tracker audio backend
at dev 46 lines 1.2 kB view raw
1use std::error::Error; 2use std::fmt::{Display, Formatter}; 3use std::io; 4 5#[derive(Debug)] 6pub enum LoadErr { 7 CantReadFile, 8 Invalid, 9 BufferTooShort, 10 IO(io::Error), 11} 12 13impl From<io::Error> for LoadErr { 14 fn from(err: io::Error) -> Self { 15 if err.kind() == io::ErrorKind::UnexpectedEof { 16 Self::BufferTooShort 17 } else { 18 Self::IO(err) 19 } 20 } 21} 22 23impl Display for LoadErr { 24 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { 25 write!(f, "{self:?}") 26 } 27} 28 29impl Error for LoadErr {} 30 31// This should be a different enum per part of file. Either return a list of these or take a callback 32// TODO: https://users.rust-lang.org/t/validation-monad/117894/6 33// 34// load was partially successful. These are the defects that are in the now loaded project 35// #[derive(Debug, Clone, Copy)] 36// #[non_exhaustive] 37// pub enum LoadDefect { 38// /// deletes the effect 39// UnknownEffect, 40// /// replaced with empty text 41// InvalidText, 42// /// tries to replace with a sane default value 43// OutOfBoundsValue, 44// /// skips loading of the pointed to value 45// OutOfBoundsPtr, 46// }