From b390685d2ef1bd2b4093a8253e8efe931a8cc8d7 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Sat, 25 May 2024 04:06:06 +0800 Subject: [PATCH] feat: const ctors for `EthAddress` and `Hash256` --- 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 } }