From 3b42e9edda0d31080d99afbffc6d3b901ee27cb8 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sun, 4 Sep 2022 02:12:25 +0100 Subject: [PATCH] Rewrite try_from_num64 via Option helpers --- src/lib.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2b20f1fe983..2ccb284b9a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -897,17 +897,14 @@ macro_rules! try_from_for_num64 { #[inline] fn try_from(v: JsValue) -> Result { - if let Some(as_i64) = bigint_get_as_i64(&v) { + bigint_get_as_i64(&v) // Reinterpret bits; ABI-wise this is safe to do and allows us to avoid // having separate intrinsics per signed/unsigned types. - let as_self = as_i64 as Self; + .map(|as_i64| as_i64 as Self) // Double-check that we didn't truncate the bigint to 64 bits. - if v == as_self { - return Ok(as_self); - } - } - // Not a bigint or not in range. - Err(v) + .filter(|as_self| v == *as_self) + // Not a bigint or not in range. + .ok_or(v) } } };