swf: Clean up a few imports

This commit is contained in:
Mads Marquart 2021-02-11 01:50:22 +01:00 committed by Mike Welsh
parent 24780003e7
commit 9243010cc0
2 changed files with 5 additions and 13 deletions

View File

@ -1,4 +1,5 @@
use std::{borrow, error, fmt, io};
use crate::tag_code::TagCode;
/// A `Result` from reading SWF data.
pub type Result<T> = std::result::Result<T, Error>;
@ -51,14 +52,6 @@ impl Error {
}
/// Helper method to create `Error::SwfParseError`.
#[inline]
pub fn swf_parse_error(tag_code: u16) -> Self {
Error::SwfParseError {
tag_code,
source: None,
}
}
/// Helper method to create `Error::SwfParseError`.
#[inline]
pub fn swf_parse_error_with_source(tag_code: u16, source: impl error::Error + 'static) -> Self {
Error::SwfParseError {
tag_code,
@ -90,10 +83,9 @@ impl fmt::Display for Error {
Ok(())
}
Error::SwfParseError { tag_code, source } => {
let tag = crate::tag_code::TagCode::from_u16(*tag_code);
"Error parsing SWF tag ".fmt(f)?;
if let Some(tag) = tag {
write!(f, "{:?}", tag)?;
if let Some(tag_code) = TagCode::from_u16(*tag_code) {
write!(f, "{:?}", tag_code)?;
} else {
write!(f, "Unknown({})", tag_code)?;
};

View File

@ -10,6 +10,7 @@ use crate::extensions::ReadSwfExt;
use crate::{
error::{Error, Result},
string::{Encoding, SwfStr},
tag_code::TagCode,
types::*,
};
use bitstream_io::BitRead;
@ -308,7 +309,6 @@ impl<'a> Reader<'a> {
fn read_tag_with_code(&mut self, tag_code: u16, length: usize) -> Result<Tag<'a>> {
let mut tag_reader = Reader::new(self.read_slice(length)?, self.version);
use crate::tag_code::TagCode;
let tag = match TagCode::from_u16(tag_code) {
Some(TagCode::End) => Tag::End,
Some(TagCode::ShowFrame) => Tag::ShowFrame,
@ -552,7 +552,7 @@ impl<'a> Reader<'a> {
Some(TagCode::VideoFrame) => tag_reader.read_video_frame()?,
Some(TagCode::ProductInfo) => Tag::ProductInfo(tag_reader.read_product_info()?),
_ => {
None => {
let data = tag_reader.read_slice_to_end();
Tag::Unknown { tag_code, data }
}