Deprecate From<EvalAltResult> for Result<T, Box<EvalAltResult>> because it is clearer for code to explicitly wrap errors in Err.

This commit is contained in:
Stephen Chung
2021-10-19 23:52:58 +08:00
parent 6d31bb0d19
commit 3001e90775
23 changed files with 226 additions and 193 deletions

View File

@@ -25,7 +25,7 @@ where
#[cfg(not(feature = "unchecked"))]
if let Some(r) = from.checked_add(&step) {
if r == from {
return EvalAltResult::ErrorInFunctionCall(
return Err(EvalAltResult::ErrorInFunctionCall(
"range".to_string(),
Default::default(),
EvalAltResult::ErrorArithmetic(
@@ -35,7 +35,7 @@ where
.into(),
crate::Position::NONE,
)
.into();
.into());
}
}
@@ -122,21 +122,27 @@ impl BitRange {
#[cfg(not(feature = "unchecked"))]
if offset >= BITS {
return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE)
.into();
return Err(
EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE).into(),
);
}
offset
} else {
#[cfg(not(feature = "unchecked"))]
if let Some(abs_from) = from.checked_abs() {
if (abs_from as usize) > BITS {
return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE)
.into();
return Err(EvalAltResult::ErrorBitFieldBounds(
BITS,
from,
crate::Position::NONE,
)
.into());
}
BITS - (abs_from as usize)
} else {
return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE)
.into();
return Err(
EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE).into(),
);
}
#[cfg(feature = "unchecked")]
@@ -325,10 +331,10 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
pub fn new(from: FLOAT, to: FLOAT, step: FLOAT) -> Result<Self, Box<EvalAltResult>> {
#[cfg(not(feature = "unchecked"))]
if step == 0.0 {
return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
return Err(EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE).into(),
crate::Position::NONE,
).into();
).into());
}
Ok(Self(from, to, step))
@@ -387,10 +393,10 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
pub fn new(from: Decimal, to: Decimal, step: Decimal) -> Result<Self, Box<EvalAltResult>> {
#[cfg(not(feature = "unchecked"))]
if step.is_zero() {
return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
return Err(EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE).into(),
crate::Position::NONE,
).into();
).into());
}
Ok(Self(from, to, step))