implement error traits

This commit is contained in:
Quaternions 2024-07-25 17:47:00 -07:00
parent e1cdddc892
commit d3e114c7b6
5 changed files with 28 additions and 4 deletions

View File

@ -1,5 +1,6 @@
use binrw::{BinReaderExt, binrw};
#[derive(Debug)]
pub enum Error{
InvalidHeader,
InvalidSegment(binrw::Error),
@ -64,7 +65,7 @@ mod simulation{
#[binrw]
#[brw(little)]
#[derive(Clone,Copy,id::Id)]
#[derive(Clone,Copy,Debug,id::Id)]
pub struct SegmentId(u32);
#[binrw]

View File

@ -1,5 +1,6 @@
use binrw::BinReaderExt;
#[derive(Debug)]
pub enum Error{
InvalidHeader,
}
@ -27,4 +28,4 @@ impl<R:BinReaderExt> StreamableDemo<R>{
pub(crate) fn new(file:crate::file::File<R>)->Result<Self,Error>{
Err(Error::InvalidHeader)
}
}
}

View File

@ -2,12 +2,19 @@
use binrw::{binrw, BinReaderExt, io::TakeSeekExt};
#[derive(Debug)]
pub enum Error{
InvalidHeader(binrw::Error),
UnexpectedEOF,
InvalidBlockId(BlockId),
Seek(std::io::Error),
}
impl std::fmt::Display for Error{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for Error{}
/* spec
@ -40,7 +47,7 @@ for block_id in 1..num_blocks{
*/
#[binrw]
#[brw(little)]
#[derive(Clone,Copy)]
#[derive(Clone,Copy,Debug)]
pub(crate) enum FourCC{
#[brw(magic=b"SNFM")]
Map,
@ -51,6 +58,7 @@ pub(crate) enum FourCC{
}
#[binrw]
#[brw(little)]
#[derive(Debug)]
pub struct Header{
/// Type of file
pub fourcc:FourCC,
@ -68,7 +76,7 @@ pub struct Header{
#[binrw]
#[brw(little)]
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
#[derive(Clone,Copy,Debug,Hash,id::Id,Eq,PartialEq)]
pub struct BlockId(u32);
pub(crate) struct File<R:BinReaderExt>{

View File

@ -7,6 +7,7 @@ pub mod map;
pub mod bot;
pub mod demo;
#[derive(Debug)]
pub enum Error{
UnexpectedFourCC,
Header(file::Error),
@ -14,6 +15,12 @@ pub enum Error{
Bot(bot::Error),
Demo(demo::Error),
}
impl std::fmt::Display for Error{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for Error{}
pub enum SNF<R:BinReaderExt>{
Map(map::StreamableMap<R>),

View File

@ -9,6 +9,7 @@ use strafesnet_common::aabb::Aabb;
use strafesnet_common::bvh::BvhNode;
use strafesnet_common::gameplay_modes;
#[derive(Debug)]
pub enum Error{
InvalidHeader(binrw::Error),
InvalidBlockId(BlockId),
@ -18,6 +19,12 @@ pub enum Error{
IO(std::io::Error),
File(crate::file::Error),
}
impl std::fmt::Display for Error{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for Error{}
/* block types