From 945145967187c8fd1c2679aebd23f1f5fc83f9b6 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Fri, 24 May 2024 14:33:54 -0600 Subject: [PATCH] feat: const ctors for `EthAddress` and `Hash256` (#591) --- starknet-core/src/types/eth_address.rs | 4 ++++ starknet-core/src/types/hash_256.rs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/starknet-core/src/types/eth_address.rs b/starknet-core/src/types/eth_address.rs index 652668f6..c380558a 100644 --- a/starknet-core/src/types/eth_address.rs +++ b/starknet-core/src/types/eth_address.rs @@ -71,6 +71,10 @@ mod errors { pub use errors::{FromBytesSliceError, FromFieldElementError, FromHexError}; impl EthAddress { + pub const fn from_bytes(bytes: [u8; 20]) -> Self { + Self { inner: bytes } + } + pub fn from_hex(hex: &str) -> Result { hex.parse() } diff --git a/starknet-core/src/types/hash_256.rs b/starknet-core/src/types/hash_256.rs index f6f9da9e..c8ccc99e 100644 --- a/starknet-core/src/types/hash_256.rs +++ b/starknet-core/src/types/hash_256.rs @@ -56,7 +56,7 @@ mod errors { pub use errors::{FromHexError, ToFieldElementError}; impl Hash256 { - pub fn from_bytes(bytes: [u8; HASH_256_BYTE_COUNT]) -> Self { + pub const fn from_bytes(bytes: [u8; HASH_256_BYTE_COUNT]) -> Self { Self { inner: bytes } }