scale_encode/impls/primitive_types.rs
1// Copyright (C) 2023 Parity Technologies (UK) Ltd. (admin@parity.io)
2// This file is a part of the scale-encode crate.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use crate::{error::Error, EncodeAsType};
17use alloc::vec::Vec;
18use primitive_types::{H128, H160, H256, H384, H512, H768};
19use scale_type_resolver::TypeResolver;
20
21macro_rules! impl_encode {
22 ($($ty:ty),*) => {$(
23 impl EncodeAsType for $ty {
24 fn encode_as_type_to<R: TypeResolver>(
25 &self,
26 type_id: R::TypeId,
27 types: &R,
28 out: &mut Vec<u8>,
29 ) -> Result<(), Error> {
30 let type_id = super::find_single_entry_with_same_repr(type_id, types);
31 self.0.encode_as_type_to(type_id, types, out)
32 }
33 }
34 )*}
35}
36impl_encode!(H128, H160, H256, H384, H512, H768);