From 70911a57dfc06fc79c318800e3f8f9d90f200d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Delabrouille?= Date: Mon, 26 Feb 2024 17:37:35 +0100 Subject: [PATCH 1/2] feat: impl ToBigInt and ToBigUInt --- .../starknet-types-core/src/felt/num_traits_impl.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/starknet-types-core/src/felt/num_traits_impl.rs b/crates/starknet-types-core/src/felt/num_traits_impl.rs index 886f13b..f8a75c8 100644 --- a/crates/starknet-types-core/src/felt/num_traits_impl.rs +++ b/crates/starknet-types-core/src/felt/num_traits_impl.rs @@ -1,6 +1,19 @@ use super::Felt; +use num_bigint::{ToBigInt, ToBigUint}; use num_traits::{FromPrimitive, Inv, One, Pow, ToPrimitive, Zero}; +impl ToBigInt for Felt { + fn to_bigint(&self) -> Option { + Some(self.to_bigint()) + } +} + +impl ToBigUint for Felt { + fn to_biguint(&self) -> Option { + Some(self.to_biguint()) + } +} + impl FromPrimitive for Felt { fn from_i64(value: i64) -> Option { Some(value.into()) From 172007e2eaaceea04972d3f4f6e34e5272f787fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Delabrouille?= Date: Fri, 8 Mar 2024 15:03:21 -0600 Subject: [PATCH 2/2] add doc about unwrap safety --- crates/starknet-types-core/src/felt/num_traits_impl.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/starknet-types-core/src/felt/num_traits_impl.rs b/crates/starknet-types-core/src/felt/num_traits_impl.rs index f8a75c8..23fd52d 100644 --- a/crates/starknet-types-core/src/felt/num_traits_impl.rs +++ b/crates/starknet-types-core/src/felt/num_traits_impl.rs @@ -3,12 +3,18 @@ use num_bigint::{ToBigInt, ToBigUint}; use num_traits::{FromPrimitive, Inv, One, Pow, ToPrimitive, Zero}; impl ToBigInt for Felt { + /// Converts the value of `self` to a [`BigInt`]. + /// + /// Safe to unwrap, will always return `Some`. fn to_bigint(&self) -> Option { Some(self.to_bigint()) } } impl ToBigUint for Felt { + /// Converts the value of `self` to a [`BigUint`]. + /// + /// Safe to unwrap, will always return `Some`. fn to_biguint(&self) -> Option { Some(self.to_biguint()) }