1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! Bytes converts literals into an array of bytes.
//!
//! Currently supports only integer literals of unbounded size.
//!
//! The macros are intended for small byte inputs. There is no arbitrary limit,
//! but very large inputs may result in long compilation times. For large amounts
//! of bytes, store the bytes in a file and use [`include_bytes!`] instead.
use TokenStream;
extern crate proc_macro;
/// Bytes converts literals into an array of bytes.
///
/// Currently supports only integer literals of unbounded size.
///
/// Supported literal forms:
/// - Base 16 (hex), e.g. `0xff`
/// - Base 2 (binary), e.g. `0b11111111`
///
/// Leading zeros are preserved. Zeros on the front of the number are preserved
/// as zeros in the final bytes. For example: `0x0001` will produce `[0, 1]`.
///
/// Decimal and octal literal forms are not supported.
///
/// This macro is intended for small byte inputs. There is no arbitrary limit,
/// but very large inputs may result in long compilation times. For large
/// amounts of bytes, store the bytes in a file and use [`include_bytes!`]
/// instead.
///
/// ### Examples
///
/// ```
/// let bytes = bytes_lit::bytes!(0x1);
/// assert_eq!(bytes, [1]);
/// ```
///
/// ```
/// let bytes = bytes_lit::bytes!(0xfded3f55dec47250a52a8c0bb7038e72fa6ffaae33562f77cd2b629ef7fd424d);
/// assert_eq!(bytes, [
/// 253, 237, 63, 85, 222, 196, 114, 80, 165, 42, 140, 11, 183, 3, 142, 114,
/// 250, 111, 250, 174, 51, 86, 47, 119, 205, 43, 98, 158, 247, 253, 66, 77,
/// ]);
/// ```
///
/// ```
/// let bytes = bytes_lit::bytes!(0x00000000dec47250a52a8c0bb7038e72fa6ffaae33562f77cd2b629ef7fd424d);
/// assert_eq!(bytes, [
/// 0, 0, 0, 0, 222, 196, 114, 80, 165, 42, 140, 11, 183, 3, 142, 114,
/// 250, 111, 250, 174, 51, 86, 47, 119, 205, 43, 98, 158, 247, 253, 66, 77,
/// ]);
/// ```
/// Bytesmin converts literals into an array of bytes of minimal size to capture
/// the value.
///
/// Currently supports only integer literals of unbounded size.
///
/// Supported literal forms:
/// - Base 16 (hex), e.g. `0xff`
/// - Base 2 (binary), e.g. `0b11111111`
///
/// Leading zeroes on integer literals are discarded and not preserved. The
/// generated byte slice is the minimal bytes required to capture the literal
/// provided.
///
/// Decimal and octal literal forms are not supported.
///
/// To preserve leading zeros, use [`bytes!`].
///
/// This macro is intended for small byte inputs. There is no arbitrary limit,
/// but very large inputs may result in long compilation times. For large
/// amounts of bytes, store the bytes in a file and use [`include_bytes!`]
/// instead.
///
/// ### Examples
///
/// ```
/// let bytes = bytes_lit::bytesmin!(0x1);
/// assert_eq!(bytes, [1]);
/// ```
///
/// ```
/// let bytes = bytes_lit::bytesmin!(0xfded3f55dec47250a52a8c0bb7038e72fa6ffaae33562f77cd2b629ef7fd424d);
/// assert_eq!(bytes, [
/// 253, 237, 63, 85, 222, 196, 114, 80, 165, 42, 140, 11, 183, 3, 142, 114,
/// 250, 111, 250, 174, 51, 86, 47, 119, 205, 43, 98, 158, 247, 253, 66, 77,
/// ]);
/// ```
///
/// ```
/// let bytes = bytes_lit::bytesmin!(0x00000000dec47250a52a8c0bb7038e72fa6ffaae33562f77cd2b629ef7fd424d);
/// assert_eq!(bytes, [
/// 222, 196, 114, 80, 165, 42, 140, 11, 183, 3, 142, 114, 250, 111, 250,
/// 174, 51, 86, 47, 119, 205, 43, 98, 158, 247, 253, 66, 77,
/// ]);
/// ```