mini_parser: Rename MiniParserError to Error

This commit is contained in:
Simon Bruder 2020-08-07 13:14:03 +02:00
parent d5aa75c43a
commit a252a3d444
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F
4 changed files with 15 additions and 12 deletions

View file

@ -28,7 +28,7 @@ pub enum Error {
#[error(transparent)] #[error(transparent)]
TryFromIntError(#[from] num::TryFromIntError), TryFromIntError(#[from] num::TryFromIntError),
#[error(transparent)] #[error(transparent)]
MiniParserError(#[from] mini_parser::MiniParserError), MiniParserError(#[from] mini_parser::Error),
} }
type Result<T> = std::result::Result<T, Error>; type Result<T> = std::result::Result<T, Error>;

View file

@ -11,7 +11,7 @@ use derive_more::Deref;
use log::{debug, info, trace, warn}; use log::{debug, info, trace, warn};
use thiserror::Error; use thiserror::Error;
use crate::mini_parser::{MiniParser, MiniParserError}; use crate::mini_parser::MiniParser;
use crate::utils; use crate::utils;
const MEASURE_LENGTH: f32 = 4096.0; const MEASURE_LENGTH: f32 = 4096.0;
@ -29,7 +29,7 @@ pub enum Error {
#[error(transparent)] #[error(transparent)]
TryFromIntError(#[from] num::TryFromIntError), TryFromIntError(#[from] num::TryFromIntError),
#[error(transparent)] #[error(transparent)]
MiniParserError(#[from] MiniParserError), MiniParserError(#[from] crate::mini_parser::Error),
} }
/// Convert time offset to beats /// Convert time offset to beats

View file

@ -7,7 +7,7 @@ use std::ops::Range;
use thiserror::Error; use thiserror::Error;
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum MiniParserError { pub enum Error {
#[error(transparent)] #[error(transparent)]
TryFromIntError(#[from] num::TryFromIntError), TryFromIntError(#[from] num::TryFromIntError),
#[error(transparent)] #[error(transparent)]
@ -20,7 +20,7 @@ pub enum MiniParserError {
pub trait MiniParser: io::Read { pub trait MiniParser: io::Read {
/// Read a `String` of length `length` and strip NUL bytes. /// Read a `String` of length `length` and strip NUL bytes.
#[inline] #[inline]
fn read_string(&mut self, length: usize) -> Result<String, MiniParserError> { fn read_string(&mut self, length: usize) -> Result<String, Error> {
let mut buf = String::new(); let mut buf = String::new();
self.take(length.try_into()?).read_to_string(&mut buf)?; self.take(length.try_into()?).read_to_string(&mut buf)?;
Ok(buf.replace("\0", "")) Ok(buf.replace("\0", ""))
@ -28,7 +28,7 @@ pub trait MiniParser: io::Read {
/// Read `n` `i32`. /// Read `n` `i32`.
#[inline] #[inline]
fn read_n_i32(&mut self, n: usize) -> Result<Vec<i32>, MiniParserError> { fn read_n_i32(&mut self, n: usize) -> Result<Vec<i32>, Error> {
let mut buf = vec![0; 4 * n]; let mut buf = vec![0; 4 * n];
self.read_exact(&mut buf)?; self.read_exact(&mut buf)?;
Ok(buf Ok(buf
@ -44,8 +44,8 @@ impl<R: io::Read + ?Sized> MiniParser for R {}
/// Gets the requested `range` from `slice` and errors with `UnexpectedEof` when range does not fit /// Gets the requested `range` from `slice` and errors with `UnexpectedEof` when range does not fit
/// in slice. /// in slice.
pub fn get_slice_range(slice: &[u8], range: Range<usize>) -> Result<&[u8], MiniParserError> { pub fn get_slice_range(slice: &[u8], range: Range<usize>) -> Result<&[u8], Error> {
slice.get(range).ok_or(MiniParserError::UnexpectedEof) slice.get(range).ok_or(Error::UnexpectedEof)
} }
#[cfg(test)] #[cfg(test)]

View file

@ -11,7 +11,7 @@ use num_traits::FromPrimitive;
use thiserror::Error; use thiserror::Error;
use crate::mini_parser; use crate::mini_parser;
use crate::mini_parser::{MiniParser, MiniParserError}; use crate::mini_parser::MiniParser;
use crate::xact3::adpcm; use crate::xact3::adpcm;
#[derive(Error, Debug)] #[derive(Error, Debug)]
@ -23,7 +23,7 @@ pub enum Error {
#[error(transparent)] #[error(transparent)]
IOError(#[from] io::Error), IOError(#[from] io::Error),
#[error(transparent)] #[error(transparent)]
MiniParserError(#[from] MiniParserError), MiniParserError(#[from] crate::mini_parser::Error),
#[error(transparent)] #[error(transparent)]
ADPCMError(#[from] adpcm::Error), ADPCMError(#[from] adpcm::Error),
#[error(transparent)] #[error(transparent)]
@ -82,8 +82,11 @@ struct SegmentPosition {
} }
impl SegmentPosition { impl SegmentPosition {
fn get_from<'a>(&self, data: &'a [u8]) -> Result<&'a [u8], MiniParserError> { fn get_from<'a>(&self, data: &'a [u8]) -> Result<&'a [u8], Error> {
mini_parser::get_slice_range(data, self.offset..self.offset + self.length) Ok(mini_parser::get_slice_range(
data,
self.offset..self.offset + self.length,
)?)
} }
} }