diff --git a/src/ddr/arc.rs b/src/ddr/arc.rs index 9af9864..3810e22 100644 --- a/src/ddr/arc.rs +++ b/src/ddr/arc.rs @@ -28,7 +28,7 @@ pub enum Error { #[error(transparent)] TryFromIntError(#[from] num::TryFromIntError), #[error(transparent)] - MiniParserError(#[from] mini_parser::MiniParserError), + MiniParserError(#[from] mini_parser::Error), } type Result = std::result::Result; diff --git a/src/ddr/ssq.rs b/src/ddr/ssq.rs index 0526f00..12c5ba2 100644 --- a/src/ddr/ssq.rs +++ b/src/ddr/ssq.rs @@ -11,7 +11,7 @@ use derive_more::Deref; use log::{debug, info, trace, warn}; use thiserror::Error; -use crate::mini_parser::{MiniParser, MiniParserError}; +use crate::mini_parser::MiniParser; use crate::utils; const MEASURE_LENGTH: f32 = 4096.0; @@ -29,7 +29,7 @@ pub enum Error { #[error(transparent)] TryFromIntError(#[from] num::TryFromIntError), #[error(transparent)] - MiniParserError(#[from] MiniParserError), + MiniParserError(#[from] crate::mini_parser::Error), } /// Convert time offset to beats diff --git a/src/mini_parser.rs b/src/mini_parser.rs index 072d726..4a0d4e4 100644 --- a/src/mini_parser.rs +++ b/src/mini_parser.rs @@ -7,7 +7,7 @@ use std::ops::Range; use thiserror::Error; #[derive(Error, Debug)] -pub enum MiniParserError { +pub enum Error { #[error(transparent)] TryFromIntError(#[from] num::TryFromIntError), #[error(transparent)] @@ -20,7 +20,7 @@ pub enum MiniParserError { pub trait MiniParser: io::Read { /// Read a `String` of length `length` and strip NUL bytes. #[inline] - fn read_string(&mut self, length: usize) -> Result { + fn read_string(&mut self, length: usize) -> Result { let mut buf = String::new(); self.take(length.try_into()?).read_to_string(&mut buf)?; Ok(buf.replace("\0", "")) @@ -28,7 +28,7 @@ pub trait MiniParser: io::Read { /// Read `n` `i32`. #[inline] - fn read_n_i32(&mut self, n: usize) -> Result, MiniParserError> { + fn read_n_i32(&mut self, n: usize) -> Result, Error> { let mut buf = vec![0; 4 * n]; self.read_exact(&mut buf)?; Ok(buf @@ -44,8 +44,8 @@ impl MiniParser for R {} /// Gets the requested `range` from `slice` and errors with `UnexpectedEof` when range does not fit /// in slice. -pub fn get_slice_range(slice: &[u8], range: Range) -> Result<&[u8], MiniParserError> { - slice.get(range).ok_or(MiniParserError::UnexpectedEof) +pub fn get_slice_range(slice: &[u8], range: Range) -> Result<&[u8], Error> { + slice.get(range).ok_or(Error::UnexpectedEof) } #[cfg(test)] diff --git a/src/xact3/xwb.rs b/src/xact3/xwb.rs index b8d95b3..c8f2231 100644 --- a/src/xact3/xwb.rs +++ b/src/xact3/xwb.rs @@ -11,7 +11,7 @@ use num_traits::FromPrimitive; use thiserror::Error; use crate::mini_parser; -use crate::mini_parser::{MiniParser, MiniParserError}; +use crate::mini_parser::MiniParser; use crate::xact3::adpcm; #[derive(Error, Debug)] @@ -23,7 +23,7 @@ pub enum Error { #[error(transparent)] IOError(#[from] io::Error), #[error(transparent)] - MiniParserError(#[from] MiniParserError), + MiniParserError(#[from] crate::mini_parser::Error), #[error(transparent)] ADPCMError(#[from] adpcm::Error), #[error(transparent)] @@ -82,8 +82,11 @@ struct SegmentPosition { } impl SegmentPosition { - fn get_from<'a>(&self, data: &'a [u8]) -> Result<&'a [u8], MiniParserError> { - mini_parser::get_slice_range(data, self.offset..self.offset + self.length) + fn get_from<'a>(&self, data: &'a [u8]) -> Result<&'a [u8], Error> { + Ok(mini_parser::get_slice_range( + data, + self.offset..self.offset + self.length, + )?) } }