From 2b0b66ddca1b5b9bba4539a183053074124f3b49 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Thu, 25 Jun 2020 18:47:11 +0200 Subject: [PATCH] Use unwrap() for writing to cursor Writing to cursors should never fail --- src/xact3/adpcm.rs | 15 +++++++-------- src/xact3/xwb.rs | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/xact3/adpcm.rs b/src/xact3/adpcm.rs index bd20b13..cd8ca8a 100644 --- a/src/xact3/adpcm.rs +++ b/src/xact3/adpcm.rs @@ -1,6 +1,5 @@ use std::io::{Cursor, Write}; -use anyhow::Result; use byteorder::{LittleEndian, WriteBytesExt}; use log::{debug, trace}; @@ -88,7 +87,7 @@ impl WaveChunk for RIFFHeader { } } -pub fn build_wav(format: WaveFormat, data: &[u8]) -> Result> { +pub fn build_wav(format: WaveFormat, data: &[u8]) -> Vec { debug!("Building file"); let riff_header = RIFFHeader { file_size: 82 + data.len() as u32, @@ -104,15 +103,15 @@ pub fn build_wav(format: WaveFormat, data: &[u8]) -> Result> { let mut buf = Cursor::new(Vec::new()); trace!("Building RIFF header"); - buf.write_all(&riff_header.to_chunk())?; + buf.write_all(&riff_header.to_chunk()).unwrap(); trace!("Building fmt chunk"); - buf.write_all(&format.to_chunk())?; + buf.write_all(&format.to_chunk()).unwrap(); trace!("Building fact chunk"); - buf.write_all(&fact.to_chunk())?; + buf.write_all(&fact.to_chunk()).unwrap(); - write!(buf, "data")?; + write!(buf, "data").unwrap(); buf.write_u32::(data.len() as u32).unwrap(); - buf.write_all(data)?; + buf.write_all(data).unwrap(); - Ok(buf.into_inner()) + buf.into_inner() } diff --git a/src/xact3/xwb.rs b/src/xact3/xwb.rs index ff70729..70d6d88 100644 --- a/src/xact3/xwb.rs +++ b/src/xact3/xwb.rs @@ -244,7 +244,7 @@ pub struct Sound<'a> { impl Sound<'_> { pub fn to_wav(&self) -> Result> { match &self.format.tag { - FormatTag::ADPCM => adpcm::build_wav(self.format.clone().try_into()?, self.data), + FormatTag::ADPCM => Ok(adpcm::build_wav(self.format.clone().try_into()?, self.data)), _ => Err(Error::UnsupportedFormat(self.format.tag.clone()).into()), } }