issue-1224 Change to map_err instead of match

This commit is contained in:
MinGyo Jung
2019-08-26 14:20:40 +09:00
parent 190e617b5e
commit ee6450e3a7

View File

@@ -1230,25 +1230,20 @@ fn do_cformat_specifier(
}
Ok(format_spec.format_number(objint::get_value(&obj)))
}
CFormatType::Float(_) => {
let result = if objtype::isinstance(&obj, &vm.ctx.float_type()) {
format_spec.format_float(objfloat::get_value(&obj))
} else if objtype::isinstance(&obj, &vm.ctx.int_type()) {
format_spec.format_float(objint::get_value(&obj).to_f64().unwrap())
} else {
let required_type_string = "an floating point or integer";
return Err(vm.new_type_error(format!(
"%{} format: {} is required, not {}",
format_spec.format_char,
required_type_string,
obj.class()
)));
};
match result {
Ok(transformed) => Ok(transformed),
Err(error) => Err(vm.new_not_implemented_error(error)),
}
CFormatType::Float(_) => if objtype::isinstance(&obj, &vm.ctx.float_type()) {
format_spec.format_float(objfloat::get_value(&obj))
} else if objtype::isinstance(&obj, &vm.ctx.int_type()) {
format_spec.format_float(objint::get_value(&obj).to_f64().unwrap())
} else {
let required_type_string = "an floating point or integer";
return Err(vm.new_type_error(format!(
"%{} format: {} is required, not {}",
format_spec.format_char,
required_type_string,
obj.class()
)));
}
.map_err(|e| vm.new_not_implemented_error(e)),
CFormatType::Character => {
let char_string = {
if objtype::isinstance(&obj, &vm.ctx.int_type()) {