use binrw::BinReaderExt; pub mod file; pub mod map; pub mod bot; pub mod demo; pub enum Error{ UnexpectedFourCC, Header(file::Error), Map(map::Error), Bot(bot::Error), Demo(demo::Error), } pub enum SNF<R:BinReaderExt>{ Map(map::StreamableMap<R>), Bot(bot::StreamableBot<R>), Demo(demo::StreamableDemo<R>), } pub fn read_snf<R:BinReaderExt>(input:R)->Result<SNF<R>,Error>{ let file=file::File::new(input).map_err(|e|Error::Header(e))?; Ok(match file.fourcc(){ file::FourCC::Map=>SNF::Map(map::StreamableMap::new(file).map_err(|e|Error::Map(e))?), file::FourCC::Bot=>SNF::Bot(bot::StreamableBot::new(file).map_err(|e|Error::Bot(e))?), file::FourCC::Demo=>SNF::Demo(demo::StreamableDemo::new(file).map_err(|e|Error::Demo(e))?), }) } pub fn read_map<R:BinReaderExt>(input:R)->Result<map::StreamableMap<R>,Error>{ let file=file::File::new(input).map_err(|e|Error::Header(e))?; match file.fourcc(){ file::FourCC::Map=>Ok(map::StreamableMap::new(file).map_err(|e|Error::Map(e))?), _=>Err(Error::UnexpectedFourCC) } } pub fn read_bot<R:BinReaderExt>(input:R)->Result<bot::StreamableBot<R>,Error>{ let file=file::File::new(input).map_err(|e|Error::Header(e))?; match file.fourcc(){ file::FourCC::Bot=>Ok(bot::StreamableBot::new(file).map_err(|e|Error::Bot(e))?), _=>Err(Error::UnexpectedFourCC) } } pub fn read_demo<R:BinReaderExt>(input:R)->Result<demo::StreamableDemo<R>,Error>{ let file=file::File::new(input).map_err(|e|Error::Header(e))?; match file.fourcc(){ file::FourCC::Demo=>Ok(demo::StreamableDemo::new(file).map_err(|e|Error::Demo(e))?), _=>Err(Error::UnexpectedFourCC) } } #[cfg(test)] mod tests { //use super::*; #[test] fn test() { } }