From 4bc8a5db3c86f017e8be7dc43531a2cb6db011c0 Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Tue, 12 Dec 2023 13:58:43 -0300 Subject: [PATCH] Implement Felt from bool --- crates/starknet-types-core/src/felt.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/starknet-types-core/src/felt.rs b/crates/starknet-types-core/src/felt.rs index 41b27d4..9dbc389 100644 --- a/crates/starknet-types-core/src/felt.rs +++ b/crates/starknet-types-core/src/felt.rs @@ -444,6 +444,15 @@ impl From for Felt { } } +impl From 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 { @@ -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); + } }