Replace unwrap with expect.
This commit is contained in:
@@ -45,29 +45,31 @@ fn collect_fn_metadata(ctx: NativeCallContext) -> crate::Array {
|
||||
namespace: Option<Identifier>,
|
||||
f: &ScriptFnDef,
|
||||
) -> Map {
|
||||
const DICT: &str = "never fails because the dictionary is pre-filled with all the keys";
|
||||
|
||||
let mut map = Map::new();
|
||||
|
||||
if let Some(ns) = namespace {
|
||||
map.insert(dict.get("namespace").unwrap().clone().into(), ns.into());
|
||||
map.insert(dict.get("namespace").expect(DICT).clone().into(), ns.into());
|
||||
}
|
||||
map.insert(
|
||||
dict.get("name").unwrap().clone().into(),
|
||||
dict.get("name").expect(DICT).clone().into(),
|
||||
f.name.clone().into(),
|
||||
);
|
||||
map.insert(
|
||||
dict.get("access").unwrap().clone().into(),
|
||||
dict.get("access").expect(DICT).clone().into(),
|
||||
match f.access {
|
||||
FnAccess::Public => dict.get("public").unwrap().clone(),
|
||||
FnAccess::Private => dict.get("private").unwrap().clone(),
|
||||
FnAccess::Public => dict.get("public").expect(DICT).clone(),
|
||||
FnAccess::Private => dict.get("private").expect(DICT).clone(),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
map.insert(
|
||||
dict.get("is_anonymous").unwrap().clone().into(),
|
||||
dict.get("is_anonymous").expect(DICT).clone().into(),
|
||||
f.name.starts_with(crate::engine::FN_ANONYMOUS).into(),
|
||||
);
|
||||
map.insert(
|
||||
dict.get("params").unwrap().clone().into(),
|
||||
dict.get("params").expect(DICT).clone().into(),
|
||||
f.params
|
||||
.iter()
|
||||
.cloned()
|
||||
|
@@ -311,12 +311,8 @@ mod decimal_functions {
|
||||
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn sqrt(x: Decimal) -> Result<Decimal, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) {
|
||||
x.sqrt()
|
||||
.ok_or_else(|| make_err(format!("Error taking the square root of {}", x,)))
|
||||
} else {
|
||||
Ok(x.sqrt().unwrap())
|
||||
}
|
||||
x.sqrt()
|
||||
.ok_or_else(|| make_err(format!("Error taking the square root of {}", x,)))
|
||||
}
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn exp(x: Decimal) -> Result<Decimal, Box<EvalAltResult>> {
|
||||
|
@@ -27,9 +27,9 @@ pub fn print_with_func(
|
||||
value: &mut Dynamic,
|
||||
) -> crate::ImmutableString {
|
||||
match ctx.call_fn_dynamic_raw(fn_name, true, &mut [value]) {
|
||||
Ok(result) if result.is::<crate::ImmutableString>() => {
|
||||
result.take_immutable_string().unwrap()
|
||||
}
|
||||
Ok(result) if result.is::<crate::ImmutableString>() => result
|
||||
.take_immutable_string()
|
||||
.expect("never fails as the result is `ImmutableString`"),
|
||||
Ok(result) => ctx.engine().map_type_name(result.type_name()).into(),
|
||||
Err(_) => ctx.engine().map_type_name(value.type_name()).into(),
|
||||
}
|
||||
|
Reference in New Issue
Block a user