use std::fmt::{self, Display};
#[derive(Clone, Copy, Debug)]
pub enum FileType {
Module,
Instrument,
Sample,
}
#[derive(Clone, Copy, Debug)]
pub struct ScanError(());
pub fn scan(input: &[u8]) -> Result<FileType, ScanError> {
match input {
[b'I', b'M', b'P', b'M', ..] => Ok(FileType::Module),
[b'I', b'M', b'P', b'I', ..] => Ok(FileType::Instrument),
[b'I', b'M', b'P', b'S', ..] => Ok(FileType::Sample),
_ => Err(ScanError(())),
}
}
impl Display for ScanError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("no Impulse Tracker magic number was recognized")
}
}
impl std::error::Error for ScanError {}