Remove try! calls for Rust 2018

This commit is contained in:
Mike Welsh 2019-04-22 23:22:19 -07:00
parent d23a489886
commit cc3327f26e
3 changed files with 50 additions and 50 deletions

View File

@ -24,7 +24,7 @@ impl<R: Read> Reader<R> {
pub fn read_action_list(&mut self) -> Result<Vec<Action>> {
let mut actions = Vec::new();
while let Some(action) = try!(self.read_action()) {
while let Some(action) = self.read_action()? {
actions.push(action);
}
Ok(actions)
@ -33,7 +33,7 @@ impl<R: Read> Reader<R> {
pub fn read_action(&mut self) -> Result<Option<Action>> {
use num_traits::FromPrimitive;
let (opcode, length) = try!(self.read_opcode_and_length());
let (opcode, length) = self.read_opcode_and_length()?;
let mut action_reader = Reader::new(self.inner.by_ref().take(length as u64), self.version);
@ -82,11 +82,11 @@ impl<R: Read> Reader<R> {
OpCode::GetProperty => Action::GetProperty,
OpCode::GetTime => Action::GetTime,
OpCode::GetUrl => Action::GetUrl {
url: try!(action_reader.read_c_string()),
target: try!(action_reader.read_c_string()),
url: action_reader.read_c_string()?,
target: action_reader.read_c_string()?,
},
OpCode::GetUrl2 => {
let flags = try!(action_reader.read_u8());
let flags = action_reader.read_u8()?;
Action::GetUrl2 {
is_target_sprite: flags & 0b10 != 0,
is_load_vars: flags & 0b1 != 0,
@ -105,29 +105,29 @@ impl<R: Read> Reader<R> {
}
OpCode::GetVariable => Action::GetVariable,
OpCode::GotoFrame => {
let frame = try!(action_reader.read_u16());
let frame = action_reader.read_u16()?;
Action::GotoFrame(frame)
}
OpCode::GotoFrame2 => {
let flags = try!(action_reader.read_u8());
let flags = action_reader.read_u8()?;
Action::GotoFrame2 {
set_playing: flags & 0b1 != 0,
scene_offset: if flags & 0b10 != 0 {
try!(action_reader.read_u16())
action_reader.read_u16()?
} else {
0
},
}
}
OpCode::GotoLabel => Action::GotoLabel(try!(action_reader.read_c_string())),
OpCode::GotoLabel => Action::GotoLabel(action_reader.read_c_string()?),
OpCode::Greater => Action::Greater,
OpCode::If => Action::If { offset: try!(action_reader.read_i16()) },
OpCode::If => Action::If { offset: action_reader.read_i16()? },
OpCode::ImplementsOp => Action::ImplementsOp,
OpCode::Increment => Action::Increment,
OpCode::InitArray => Action::InitArray,
OpCode::InitObject => Action::InitObject,
OpCode::InstanceOf => Action::InstanceOf,
OpCode::Jump => Action::Jump { offset: try!(action_reader.read_i16()) },
OpCode::Jump => Action::Jump { offset: action_reader.read_i16()? },
OpCode::Less => Action::Less,
OpCode::Less2 => Action::Less2,
OpCode::MBAsciiToChar => Action::MBAsciiToChar,
@ -184,8 +184,8 @@ impl<R: Read> Reader<R> {
OpCode::Try => action_reader.read_try()?,
OpCode::TypeOf => Action::TypeOf,
OpCode::WaitForFrame => Action::WaitForFrame {
frame: try!(action_reader.read_u16()),
num_actions_to_skip: try!(action_reader.read_u8()),
frame: action_reader.read_u16()?,
num_actions_to_skip: action_reader.read_u8()?,
},
OpCode::With => {
let code_length = action_reader.read_u16()?;
@ -196,7 +196,7 @@ impl<R: Read> Reader<R> {
Action::With { actions: with_reader.read_action_list()? }
}
OpCode::WaitForFrame2 => Action::WaitForFrame2 {
num_actions_to_skip: try!(action_reader.read_u8()),
num_actions_to_skip: action_reader.read_u8()?,
},
}
} else {
@ -207,9 +207,9 @@ impl<R: Read> Reader<R> {
}
pub fn read_opcode_and_length(&mut self) -> Result<(u8, usize)> {
let opcode = try!(self.read_u8());
let opcode = self.read_u8()?;
let length = if opcode >= 0x80 {
try!(self.read_u16()) as usize
self.read_u16()? as usize
} else {
0
};
@ -226,17 +226,17 @@ impl<R: Read> Reader<R> {
}
fn read_push_value(&mut self) -> Result<Value> {
let value = match try!(self.read_u8()) {
0 => Value::Str(try!(self.read_c_string())),
1 => Value::Float(try!(self.read_f32())),
let value = match self.read_u8()? {
0 => Value::Str(self.read_c_string()?),
1 => Value::Float(self.read_f32()?),
2 => Value::Null,
3 => Value::Undefined,
4 => Value::Register(try!(self.read_u8())),
5 => Value::Bool(try!(self.read_u8()) != 0),
6 => Value::Double(try!(self.read_f64())),
7 => Value::Int(try!(self.read_u32())),
8 => Value::ConstantPool(try!(self.read_u8()) as u16),
9 => Value::ConstantPool(try!(self.read_u16())),
4 => Value::Register(self.read_u8()?),
5 => Value::Bool(self.read_u8()? != 0),
6 => Value::Double(self.read_f64()?),
7 => Value::Int(self.read_u32()?),
8 => Value::ConstantPool(self.read_u8()? as u16),
9 => Value::ConstantPool(self.read_u16()?),
_ => {
return Err(Error::new(
ErrorKind::InvalidData,
@ -332,7 +332,7 @@ impl<R: Read> Reader<R> {
fn_reader.read_action_list()?
};
Ok(Action::Try(TryBlock {
try: try_actions,
try_actions,
catch: if flags & 0b1 != 0 {
Some((catch_var, catch_actions))
} else {

View File

@ -157,7 +157,7 @@ pub struct FunctionParam {
#[derive(Clone, Debug, PartialEq)]
pub struct TryBlock {
pub try: Vec<Action>,
pub try_actions: Vec<Action>,
pub catch: Option<(CatchVar, Vec<Action>)>,
pub finally: Option<Vec<Action>>,
}

View File

@ -24,9 +24,9 @@ impl<W: Write> Writer<W> {
pub fn write_action_list(&mut self, actions: &[Action]) -> Result<()> {
for action in actions {
try!(self.write_action(action));
self.write_action(action)?;
}
try!(self.write_u8(0)); // End
self.write_u8(0)?; // End
Ok(())
}
@ -287,7 +287,7 @@ impl<W: Write> Writer<W> {
let mut action_buf = vec![];
{
let mut fn_writer = Writer::new(&mut action_buf, self.version);
fn_writer.write_action_list(&try_block.try)?;
fn_writer.write_action_list(&try_block.try_actions)?;
try_length = fn_writer.inner.len();
if let Some((_, ref catch)) = try_block.catch {
fn_writer.write_action_list(catch)?;
@ -359,13 +359,13 @@ impl<W: Write> Writer<W> {
}
pub fn write_opcode_and_length(&mut self, opcode: u8, length: usize) -> Result<()> {
try!(self.write_u8(opcode));
self.write_u8(opcode)?;
assert!(
opcode >= 0x80 || length == 0,
"Opcodes less than 0x80 must have length 0"
);
if opcode >= 0x80 {
try!(self.write_u16(length as u16));
self.write_u16(length as u16)?;
}
Ok(())
}
@ -373,42 +373,42 @@ impl<W: Write> Writer<W> {
fn write_push_value(&mut self, value: &Value) -> Result<()> {
match *value {
Value::Str(ref string) => {
try!(self.write_u8(0));
try!(self.write_c_string(string));
self.write_u8(0)?;
self.write_c_string(string)?;
}
Value::Float(v) => {
try!(self.write_u8(1));
try!(self.write_f32(v));
self.write_u8(1)?;
self.write_f32(v)?;
}
Value::Null => {
try!(self.write_u8(2));
self.write_u8(2)?;
}
Value::Undefined => {
try!(self.write_u8(3));
self.write_u8(3)?;
}
Value::Register(v) => {
try!(self.write_u8(4));
try!(self.write_u8(v));
self.write_u8(4)?;
self.write_u8(v)?;
}
Value::Bool(v) => {
try!(self.write_u8(5));
try!(self.write_u8(v as u8));
self.write_u8(5)?;
self.write_u8(v as u8)?;
}
Value::Double(v) => {
try!(self.write_u8(6));
try!(self.write_f64(v));
self.write_u8(6)?;
self.write_f64(v)?;
}
Value::Int(v) => {
try!(self.write_u8(7));
try!(self.write_u32(v));
self.write_u8(7)?;
self.write_u32(v)?;
}
Value::ConstantPool(v) => {
if v < 256 {
try!(self.write_u8(8));
try!(self.write_u8(v as u8));
self.write_u8(8)?;
self.write_u8(v as u8)?;
} else {
try!(self.write_u8(9));
try!(self.write_u16(v));
self.write_u8(9)?;
self.write_u16(v)?;
}
}
};