mini_parser: Rename MiniParserError to Error
This commit is contained in:
parent
d5aa75c43a
commit
a252a3d444
|
@ -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<T> = std::result::Result<T, Error>;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<String, MiniParserError> {
|
||||
fn read_string(&mut self, length: usize) -> Result<String, Error> {
|
||||
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<Vec<i32>, MiniParserError> {
|
||||
fn read_n_i32(&mut self, n: usize) -> Result<Vec<i32>, Error> {
|
||||
let mut buf = vec![0; 4 * n];
|
||||
self.read_exact(&mut 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
|
||||
/// in slice.
|
||||
pub fn get_slice_range(slice: &[u8], range: Range<usize>) -> Result<&[u8], MiniParserError> {
|
||||
slice.get(range).ok_or(MiniParserError::UnexpectedEof)
|
||||
pub fn get_slice_range(slice: &[u8], range: Range<usize>) -> Result<&[u8], Error> {
|
||||
slice.get(range).ok_or(Error::UnexpectedEof)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -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,
|
||||
)?)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue