From 0b630576d4b2402277d55f0a53e9d048a31af9aa Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 13 Feb 2024 21:27:28 -0800 Subject: [PATCH] wrapped types + implement error trait --- src/lib.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3b35ed8..20f397a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,24 +3,34 @@ use std::io::Read; mod rbx; mod primitives; +pub struct Dom(rbx_dom_weak::WeakDom); + #[derive(Debug)] -pub enum Error{ +pub enum ReadError{ RbxBinary(rbx_binary::DecodeError), RbxXml(rbx_xml::DecodeError), Io(std::io::Error), UnknownFileFormat, } +impl std::fmt::Display for ReadError{ + fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ + write!(f,"{self:?}") + } +} +impl std::error::Error for ReadError{} -fn load_dom(input:R)->Result{ +pub fn read(input:R)->Result{ let mut buf=std::io::BufReader::new(input); - let peek=std::io::BufRead::fill_buf(&mut buf).map_err(Error::Io)?; + let peek=std::io::BufRead::fill_buf(&mut buf).map_err(ReadError::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), + b"rbx_binary::from_reader(buf).map(Dom).map_err(ReadError::RbxBinary), + b"rbx_xml::from_reader_default(buf).map(Dom).map_err(ReadError::RbxXml), + _=>Err(ReadError::UnknownFileFormat), } } -pub fn readOption>(input:R,acquire_id:F)->Result{ - Ok(rbx::convert(load_dom(input)?,acquire_id)) +//ConvertError + +pub fn convertOption>(dom:&Dom,acquire_id:F)->strafesnet_common::map::CompleteMap{ + rbx::convert(&dom.0,acquire_id) } \ No newline at end of file