From 573c58988585517bcc1afb0b3e87cd310bafc221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Delabrouille?= <34384633+tdelabro@users.noreply.github.com> Date: Tue, 25 Jun 2024 13:04:29 +0200 Subject: [PATCH] feat: impl ToBigInt and ToBigUInt (#42) --- .../src/felt/num_traits_impl.rs | 19 +++++++++++++++++++ 1 file changed, 19 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 886f13b8..23fd52d2 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,25 @@ use super::Felt; +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()) + } +} + impl FromPrimitive for Felt { fn from_i64(value: i64) -> Option { Some(value.into())