From 9026eee5d699d07f023f6c0a55f305ec472f3a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Fri, 30 Oct 2020 15:29:42 +0100 Subject: [PATCH] Add constant constructor to AccountId32 (#7471) --- substrate/primitives/core/src/crypto.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index c1490f882b..6606b88887 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -617,6 +617,16 @@ pub trait Public: #[cfg_attr(feature = "std", derive(Hash))] pub struct AccountId32([u8; 32]); +impl AccountId32 { + /// Create a new instance from its raw inner byte value. + /// + /// Equivalent to this types `From<[u8; 32]>` implementation. For the lack of const + /// support in traits we have this constructor. + pub const fn new(inner: [u8; 32]) -> Self { + Self(inner) + } +} + impl UncheckedFrom for AccountId32 { fn unchecked_from(h: crate::hash::H256) -> Self { AccountId32(h.into()) @@ -651,8 +661,8 @@ impl AsMut<[u8; 32]> for AccountId32 { } impl From<[u8; 32]> for AccountId32 { - fn from(x: [u8; 32]) -> AccountId32 { - AccountId32(x) + fn from(x: [u8; 32]) -> Self { + Self::new(x) } }