Add constant constructor to AccountId32 (#7471)

This commit is contained in:
Alexander Theißen
2020-10-30 15:29:42 +01:00
committed by GitHub
parent 86d5d9609d
commit 9026eee5d6
+12 -2
View File
@@ -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<crate::hash::H256> 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)
}
}