use std::io::Read; mod rbx; mod primitives; #[derive(Debug)] pub enum Error{ RbxBinary(rbx_binary::DecodeError), RbxXml(rbx_xml::DecodeError), Io(std::io::Error), UnknownFileFormat, } fn load_dom(input:R)->Result{ let mut buf=std::io::BufReader::new(input); let peek=std::io::BufRead::fill_buf(&mut buf).map_err(Error::Io)?; match &peek[0..8]{ b"return rbx_binary::from_reader(buf).map_err(Error::RbxBinary), b"return rbx_xml::from_reader_default(buf).map_err(Error::RbxXml), _=>Err(Error::UnknownFileFormat), } } pub fn readOption>(input:R,acquire_id:F)->Result{ Ok(rbx::convert(load_dom(input)?,acquire_id)) }