wrap types + error

This commit is contained in:
Quaternions 2024-02-13 21:23:45 -08:00
parent c02e69f02c
commit 272ad40c44

View File

@ -1,18 +1,30 @@
mod bsp; mod bsp;
pub fn read<R:std::io::Read>(mut input:R)->vbsp::BspResult<vbsp::Bsp>{ pub struct Bsp(vbsp::Bsp);
#[derive(Debug)]
pub enum ReadError{
Bsp(vbsp::BspError),
Io(std::io::Error),
}
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{}
pub fn read<R:std::io::Read>(mut input:R)->Result<Bsp,ReadError>{
let mut s=Vec::new(); let mut s=Vec::new();
match input.read_to_end(&mut s){ //TODO: mmap
Ok(_)=>(), input.read_to_end(&mut s).map_err(ReadError::Io)?;
Err(e)=>println!("load_bsp::convert read_to_end failed: {:?}",e),
}
vbsp::Bsp::read(s.as_slice()) vbsp::Bsp::read(s.as_slice()).map(Bsp).map_err(ReadError::Bsp)
} }
pub fn convert<AcquireTextureId,AcquireMeshId>( pub fn convert<AcquireTextureId,AcquireMeshId>(
bsp:&vbsp::Bsp, bsp:&Bsp,
acquire_texture_id:AcquireTextureId, acquire_texture_id:AcquireTextureId,
acquire_mesh_id:AcquireMeshId acquire_mesh_id:AcquireMeshId
)->strafesnet_common::map::CompleteMap )->strafesnet_common::map::CompleteMap
@ -20,5 +32,5 @@ where
AcquireTextureId:FnMut(&str)->strafesnet_common::model::TextureId, AcquireTextureId:FnMut(&str)->strafesnet_common::model::TextureId,
AcquireMeshId:FnMut(&str)->strafesnet_common::model::MeshId, AcquireMeshId:FnMut(&str)->strafesnet_common::model::MeshId,
{ {
bsp::convert(bsp,acquire_texture_id,acquire_mesh_id) bsp::convert(&bsp.0,acquire_texture_id,acquire_mesh_id)
} }