solid_core/bytesfix/
stable.rs1use crate::{
2 decode::Decode,
3 encode::Encode,
4 into_type::IntoType,
5};
6use std::{
7 borrow::Cow,
8 convert::TryInto,
9};
10
11pub struct Bytes1(pub [u8; 1]);
12pub struct Bytes2(pub [u8; 2]);
13pub struct Bytes3(pub [u8; 3]);
14pub struct Bytes4(pub [u8; 4]);
15pub struct Bytes5(pub [u8; 5]);
16pub struct Bytes6(pub [u8; 6]);
17pub struct Bytes7(pub [u8; 7]);
18pub struct Bytes8(pub [u8; 8]);
19pub struct Bytes9(pub [u8; 9]);
20pub struct Bytes10(pub [u8; 10]);
21pub struct Bytes11(pub [u8; 11]);
22pub struct Bytes12(pub [u8; 12]);
23pub struct Bytes13(pub [u8; 13]);
24pub struct Bytes14(pub [u8; 14]);
25pub struct Bytes15(pub [u8; 15]);
26pub struct Bytes16(pub [u8; 16]);
27pub struct Bytes17(pub [u8; 17]);
28pub struct Bytes18(pub [u8; 18]);
29pub struct Bytes19(pub [u8; 19]);
30pub struct Bytes20(pub [u8; 20]);
31pub struct Bytes21(pub [u8; 21]);
32pub struct Bytes22(pub [u8; 22]);
33pub struct Bytes23(pub [u8; 23]);
34pub struct Bytes24(pub [u8; 24]);
35pub struct Bytes25(pub [u8; 25]);
36pub struct Bytes26(pub [u8; 26]);
37pub struct Bytes27(pub [u8; 27]);
38pub struct Bytes28(pub [u8; 28]);
39pub struct Bytes29(pub [u8; 29]);
40pub struct Bytes30(pub [u8; 30]);
41pub struct Bytes31(pub [u8; 31]);
42pub struct Bytes32(pub [u8; 32]);
43
44macro_rules! impl_into_type_and_encode_bytesfix {
45 ($ty: ident, $expr: expr) => {
46 impl Encode for $ty {
47 fn encode(&self) -> Vec<u8> {
48 let mut buf = vec![0u8; 32];
49 buf[0..self.0.len()].copy_from_slice(&self.0);
50 buf
51 }
52 }
53
54 impl<'a> Decode<'a> for $ty {
55 fn decode(buf: &'a [u8]) -> Self {
56 $ty(buf[0..32].try_into().unwrap())
57 }
58 }
59 impl IntoType for $ty {
60 fn into_type() -> Cow<'static, str> {
61 Cow::Borrowed($expr)
62 }
63 }
64 };
65}
66
67impl_into_type_and_encode_bytesfix!(Bytes1, "bytes1");
68impl_into_type_and_encode_bytesfix!(Bytes2, "bytes2");
69impl_into_type_and_encode_bytesfix!(Bytes3, "bytes3");
70impl_into_type_and_encode_bytesfix!(Bytes4, "bytes4");
71impl_into_type_and_encode_bytesfix!(Bytes5, "bytes5");
72impl_into_type_and_encode_bytesfix!(Bytes6, "bytes6");
73impl_into_type_and_encode_bytesfix!(Bytes7, "bytes7");
74impl_into_type_and_encode_bytesfix!(Bytes8, "bytes8");
75impl_into_type_and_encode_bytesfix!(Bytes9, "bytes9");
76impl_into_type_and_encode_bytesfix!(Bytes10, "bytes10");
77impl_into_type_and_encode_bytesfix!(Bytes11, "bytes11");
78impl_into_type_and_encode_bytesfix!(Bytes12, "bytes12");
79impl_into_type_and_encode_bytesfix!(Bytes13, "bytes13");
80impl_into_type_and_encode_bytesfix!(Bytes14, "bytes14");
81impl_into_type_and_encode_bytesfix!(Bytes15, "bytes15");
82impl_into_type_and_encode_bytesfix!(Bytes16, "bytes16");
83impl_into_type_and_encode_bytesfix!(Bytes17, "bytes17");
84impl_into_type_and_encode_bytesfix!(Bytes18, "bytes18");
85impl_into_type_and_encode_bytesfix!(Bytes19, "bytes19");
86impl_into_type_and_encode_bytesfix!(Bytes20, "bytes20");
87impl_into_type_and_encode_bytesfix!(Bytes21, "bytes21");
88impl_into_type_and_encode_bytesfix!(Bytes22, "bytes22");
89impl_into_type_and_encode_bytesfix!(Bytes23, "bytes23");
90impl_into_type_and_encode_bytesfix!(Bytes24, "bytes24");
91impl_into_type_and_encode_bytesfix!(Bytes25, "bytes25");
92impl_into_type_and_encode_bytesfix!(Bytes26, "bytes26");
93impl_into_type_and_encode_bytesfix!(Bytes27, "bytes27");
94impl_into_type_and_encode_bytesfix!(Bytes28, "bytes28");
95impl_into_type_and_encode_bytesfix!(Bytes29, "bytes29");
96impl_into_type_and_encode_bytesfix!(Bytes30, "bytes30");
97impl_into_type_and_encode_bytesfix!(Bytes31, "bytes31");
98impl_into_type_and_encode_bytesfix!(Bytes32, "bytes32");