Skip to content

Commit

Permalink
Implement Felt from bool
Browse files Browse the repository at this point in the history
  • Loading branch information
pefontana committed Dec 12, 2023
1 parent ebfebde commit 4bc8a5d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/starknet-types-core/src/felt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,15 @@ impl From<i128> for Felt {
}
}

impl From<bool> for Felt {
fn from(value: bool) -> Felt {
match value {
true => Felt::ONE,
false => Felt::ZERO,
}
}
}

macro_rules! impl_from {
($from:ty, $with:ty) => {
impl From<$from> for Felt {
Expand Down Expand Up @@ -1698,4 +1707,11 @@ mod test {
);
}
}
#[test]
fn bool_into_felt() {
let zero: Felt = false.into();
let one: Felt = true.into();
assert_eq!(one, Felt::ONE);
assert_eq!(zero, Felt::ZERO);
}
}

0 comments on commit 4bc8a5d

Please sign in to comment.