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 4, 2024
1 parent 0e9e962 commit 688f471
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ serde = { version = "1.0.130", features = ["derive", "rc"] }
serde_json = "1.0.81"
sha3 = "0.10.8"
starknet-crypto = "0.5.1"
starknet-types-core = { version = "0.1.0", features = ["hash"] }
starknet-types-core = { version = "0.1.2", features = ["hash"] }
strum = "0.24.1"
strum_macros = "0.24.3"
thiserror = "1.0.31"
Expand Down
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 688f471

Please sign in to comment.