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

View File

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

View File

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

View File

@ -7,6 +7,7 @@ pub mod map;
pub mod bot; pub mod bot;
pub mod demo; pub mod demo;
#[derive(Debug)]
pub enum Error{ pub enum Error{
UnexpectedFourCC, UnexpectedFourCC,
Header(file::Error), Header(file::Error),
@ -14,6 +15,12 @@ pub enum Error{
Bot(bot::Error), Bot(bot::Error),
Demo(demo::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>{ pub enum SNF<R:BinReaderExt>{
Map(map::StreamableMap<R>), Map(map::StreamableMap<R>),

View File

@ -9,6 +9,7 @@ use strafesnet_common::aabb::Aabb;
use strafesnet_common::bvh::BvhNode; use strafesnet_common::bvh::BvhNode;
use strafesnet_common::gameplay_modes; use strafesnet_common::gameplay_modes;
#[derive(Debug)]
pub enum Error{ pub enum Error{
InvalidHeader(binrw::Error), InvalidHeader(binrw::Error),
InvalidBlockId(BlockId), InvalidBlockId(BlockId),
@ -18,6 +19,12 @@ pub enum Error{
IO(std::io::Error), IO(std::io::Error),
File(crate::file::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 /* block types