Skip to content

Commit

Permalink
chore: implement felt! for all uint types
Browse files Browse the repository at this point in the history
Signed-off-by: Dori Medini <[email protected]>
  • Loading branch information
dorimedini-starkware committed Jun 3, 2024
1 parent 82fd726 commit 008dbf5
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ pub trait TryIntoFelt<V> {
fn to_felt_unchecked(v: V) -> Felt;
}

#[cfg(any(feature = "testing", test))]
impl TryIntoFelt<u128> for FeltConverter {
fn to_felt_unchecked(v: u128) -> Felt {
Felt::from(v)
}
macro_rules! impl_try_into_felt {
($type:ty) => {
#[cfg(any(feature = "testing", test))]
impl TryIntoFelt<$type> for FeltConverter {
fn to_felt_unchecked(v: $type) -> Felt {
Felt::from(v)
}
}
};
}

impl_try_into_felt!(u128);
impl_try_into_felt!(u64);
impl_try_into_felt!(u32);
impl_try_into_felt!(u16);
impl_try_into_felt!(u8);

#[cfg(any(feature = "testing", test))]
impl TryIntoFelt<&str> for FeltConverter {
fn to_felt_unchecked(v: &str) -> Felt {
Expand Down

0 comments on commit 008dbf5

Please sign in to comment.