8
8
//! If you were familiar with the [binary_macros] crate, this library is
9
9
//! actually [inspired][binary_macros_issue] from it.
10
10
//!
11
- //! If you use a nightly compiler, you may disable the "stable" feature:
12
- //!
13
- //! ```text
14
- //! data-encoding-macro = { version = "0.1", default-features = false }
15
- //! ```
16
- //!
17
- //! This library does not support no-std yet because it depends on a proc-macro library that depends
18
- //! on data-encoding with std and cargo propagates that feature although it's a build dependency.
19
- //! See https://github.com/rust-lang/cargo/issues/5730 for more information.
20
- //!
21
11
//! # Examples
22
12
//!
23
13
//! You can define a compile-time byte slice from an encoded string literal:
24
14
//!
25
15
//! ```rust
26
- //! # #![cfg_attr(not(feature = "stable"), feature(proc_macro_hygiene))]
27
- //! #[macro_use]
28
- //! extern crate data_encoding_macro;
29
- //!
30
- //! const HELLO_SLICE: &'static [u8] = &hexlower!("68656c6c6f");
31
- //! const FOOBAR_SLICE: &'static [u8] = &base64!("Zm9vYmFy");
16
+ //! const HELLO_SLICE: &'static [u8] = &data_encoding_macro::hexlower!("68656c6c6f");
17
+ //! const FOOBAR_SLICE: &'static [u8] = &data_encoding_macro::base64!("Zm9vYmFy");
32
18
//! # fn main() {}
33
19
//! ```
34
20
//!
35
- //! When you disable the "stable" feature (and use a nightly compiler), you can
36
- //! also define a compile-time byte array from an encoded string literal:
21
+ //! You can also define a compile-time byte array from an encoded string literal:
37
22
//!
38
23
//! ```rust
39
- //! # #[macro_use] extern crate data_encoding_macro;
40
- //! # #[cfg(not(feature = "stable"))]
41
- //! hexlower_array!("const HELLO" = "68656c6c6f");
42
- //! # #[cfg(not(feature = "stable"))]
43
- //! base64_array!("const FOOBAR" = "Zm9vYmFy");
24
+ //! data_encoding_macro::hexlower_array!("const HELLO" = "68656c6c6f");
25
+ //! data_encoding_macro::base64_array!("const FOOBAR" = "Zm9vYmFy");
44
26
//! # fn main() {}
45
27
//! ```
46
28
//!
47
29
//! You can define a compile-time custom encoding from its specification:
48
30
//!
49
31
//! ```rust
50
- //! # #![cfg_attr(not(feature = "stable"), feature(proc_macro_hygiene))]
51
- //! extern crate data_encoding;
52
- //! #[macro_use]
53
- //! extern crate data_encoding_macro;
54
- //! use data_encoding::Encoding;
55
- //!
56
- //! const HEX: Encoding = new_encoding! {
32
+ //! const HEX: data_encoding::Encoding = data_encoding_macro::new_encoding! {
57
33
//! symbols: "0123456789abcdef",
58
34
//! translate_from: "ABCDEF",
59
35
//! translate_to: "abcdef",
60
36
//! };
61
- //! const BASE64: Encoding = new_encoding! {
37
+ //! const BASE64: data_encoding:: Encoding = data_encoding_macro:: new_encoding! {
62
38
//! symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
63
39
//! padding: '=',
64
40
//! };
72
48
//! [data-encoding]: https://crates.io/crates/data-encoding
73
49
//! [hexadecimal]: macro.hexlower_permissive.html
74
50
75
- #![ cfg_attr( not( feature = "stable" ) , feature( proc_macro_hygiene) ) ]
76
- #![ warn( unused_results) ]
77
51
#![ no_std]
52
+ #![ warn( unused_results) ]
78
53
79
- #[ cfg( feature = "stable" ) ]
80
- extern crate proc_macro_hack;
81
-
82
- extern crate data_encoding;
83
- extern crate data_encoding_macro_internal;
84
-
85
- #[ cfg( feature = "stable" ) ]
86
- use proc_macro_hack:: proc_macro_hack;
87
-
88
- #[ cfg( not( feature = "stable" ) ) ]
89
- #[ doc( hidden) ]
90
- pub use data_encoding_macro_internal:: * ;
91
-
92
- #[ cfg( feature = "stable" ) ]
93
- #[ proc_macro_hack]
94
- #[ doc( hidden) ]
95
- pub use data_encoding_macro_internal:: internal_new_encoding;
96
-
97
- #[ cfg( feature = "stable" ) ]
98
- #[ proc_macro_hack]
99
54
#[ doc( hidden) ]
100
- pub use data_encoding_macro_internal:: internal_decode_slice;
55
+ pub use data_encoding_macro_internal:: {
56
+ internal_decode_array, internal_decode_slice, internal_new_encoding,
57
+ } ;
101
58
102
59
/// Defines a compile-time byte array by decoding a string literal
103
60
///
@@ -110,10 +67,7 @@ pub use data_encoding_macro_internal::internal_decode_slice;
110
67
/// # Examples
111
68
///
112
69
/// ```rust
113
- /// #[macro_use]
114
- /// extern crate data_encoding_macro;
115
- ///
116
- /// decode_array! {
70
+ /// data_encoding_macro::decode_array! {
117
71
/// name: "const OCTAL",
118
72
/// symbols: "01234567",
119
73
/// padding: '=',
@@ -123,7 +77,6 @@ pub use data_encoding_macro_internal::internal_decode_slice;
123
77
/// ```
124
78
///
125
79
/// [new_encoding]: macro.new_encoding.html
126
- #[ cfg( not( feature = "stable" ) ) ]
127
80
#[ macro_export]
128
81
macro_rules! decode_array {
129
82
( $( $arg: tt) * ) => {
@@ -141,11 +94,7 @@ macro_rules! decode_array {
141
94
/// # Examples
142
95
///
143
96
/// ```rust
144
- /// # #![feature(proc_macro_hygiene)]
145
- /// #[macro_use]
146
- /// extern crate data_encoding_macro;
147
- ///
148
- /// const OCTAL: &'static [u8] = &decode_slice! {
97
+ /// const OCTAL: &'static [u8] = &data_encoding_macro::decode_slice! {
149
98
/// symbols: "01234567",
150
99
/// padding: '=',
151
100
/// input: "237610==",
@@ -154,44 +103,13 @@ macro_rules! decode_array {
154
103
/// ```
155
104
///
156
105
/// [new_encoding]: macro.new_encoding.html
157
- #[ cfg( not( feature = "stable" ) ) ]
158
106
#[ macro_export]
159
107
macro_rules! decode_slice {
160
108
( $( $arg: tt) * ) => {
161
109
$crate:: internal_decode_slice!( $( $arg) * )
162
110
} ;
163
111
}
164
112
165
- /// Defines a compile-time byte slice by decoding a string literal
166
- ///
167
- /// This macro takes a list of `key: value,` pairs (the last comma is required).
168
- /// It takes the key-value pairs specifying the encoding to use to decode the
169
- /// input (see [new_encoding] for the possible key-value pairs), the input
170
- /// itself keyed by `input`, and the output keyed by `name`.
171
- ///
172
- /// # Examples
173
- ///
174
- /// ```rust
175
- /// #[macro_use]
176
- /// extern crate data_encoding_macro;
177
- ///
178
- /// const OCTAL: &'static [u8] = &decode_slice! {
179
- /// symbols: "01234567",
180
- /// padding: '=',
181
- /// input: "237610==",
182
- /// };
183
- /// # fn main() {}
184
- /// ```
185
- ///
186
- /// [new_encoding]: macro.new_encoding.html
187
- #[ cfg( feature = "stable" ) ]
188
- #[ macro_export]
189
- macro_rules! decode_slice {
190
- ( $( $arg: tt) * ) => {
191
- internal_decode_slice!( $( $arg) * )
192
- } ;
193
- }
194
-
195
113
/// Defines a compile-time custom encoding
196
114
///
197
115
/// This macro takes a list of `key: value,` pairs (the last comma is required).
@@ -215,57 +133,7 @@ macro_rules! decode_slice {
215
133
/// # Examples
216
134
///
217
135
/// ```rust
218
- /// # #![feature(proc_macro_hygiene)]
219
- /// extern crate data_encoding;
220
- /// #[macro_use]
221
- /// extern crate data_encoding_macro;
222
- ///
223
- /// const HEX: data_encoding::Encoding = new_encoding! {
224
- /// symbols: "0123456789abcdef",
225
- /// ignore: " \r\t\n",
226
- /// wrap_width: 32,
227
- /// wrap_separator: "\n",
228
- /// translate_from: "ABCDEF",
229
- /// translate_to: "abcdef",
230
- /// };
231
- /// # fn main() {}
232
- /// ```
233
- #[ cfg( not( feature = "stable" ) ) ]
234
- #[ macro_export]
235
- macro_rules! new_encoding {
236
- ( $( $arg: tt) * ) => {
237
- :: data_encoding:: Encoding :: internal_new( & $crate:: internal_new_encoding!{ $( $arg) * } )
238
- } ;
239
- }
240
-
241
- /// Defines a compile-time custom encoding
242
- ///
243
- /// This macro takes a list of `key: value,` pairs (the last comma is required).
244
- /// The possible key-value pairs are:
245
- ///
246
- /// ```text
247
- /// symbols: <string>, // e.g. "01234567"
248
- /// padding: [None]|<char>, // e.g. '='
249
- /// bit_order: [MostSignificantFirst]|LeastSignificantFirst,
250
- /// check_trailing_bits: [true]|false,
251
- /// ignore: [""]|<string>, // e.g. " \t\n"
252
- /// wrap_width: [0]|<int>, // e.g. 76
253
- /// wrap_separator: [""]|<string>, // e.g. "\r\n"
254
- /// translate_from: [""]|<string>, // e.g. "ABCDEF"
255
- /// translate_to: [""]|<string>, // e.g. "abcdef"
256
- /// ```
257
- ///
258
- /// Only `symbols` is required. Everything else is optional and defaults to the
259
- /// value between square brackets.
260
- ///
261
- /// # Examples
262
- ///
263
- /// ```rust
264
- /// extern crate data_encoding;
265
- /// #[macro_use]
266
- /// extern crate data_encoding_macro;
267
- ///
268
- /// const HEX: data_encoding::Encoding = new_encoding! {
136
+ /// const HEX: data_encoding::Encoding = data_encoding_macro::new_encoding! {
269
137
/// symbols: "0123456789abcdef",
270
138
/// ignore: " \r\t\n",
271
139
/// wrap_width: 32,
@@ -275,27 +143,25 @@ macro_rules! new_encoding {
275
143
/// };
276
144
/// # fn main() {}
277
145
/// ```
278
- #[ cfg( feature = "stable" ) ]
279
146
#[ macro_export]
280
147
macro_rules! new_encoding {
281
148
( $( $arg: tt) * ) => {
282
- :: data_encoding:: Encoding :: internal_new( & internal_new_encoding!{ $( $arg) * } )
149
+ data_encoding:: Encoding :: internal_new( & $crate :: internal_new_encoding!{ $( $arg) * } )
283
150
} ;
284
151
}
285
152
286
153
macro_rules! make {
287
154
( $base: ident $base_array: ident = $ref: ident; $( $spec: tt) * ) => {
288
- #[ cfg( not( feature = "stable" ) ) ]
289
155
#[ macro_export]
290
156
macro_rules! $base_array {
291
157
( $n: tt = $x: tt) => {
292
- decode_array!( name: $n, input: $x, $( $spec) * ) ;
158
+ $crate :: decode_array!( name: $n, input: $x, $( $spec) * ) ;
293
159
} ;
294
160
}
295
161
#[ macro_export]
296
162
macro_rules! $base {
297
163
( $x: tt) => {
298
- decode_slice!( input: $x, $( $spec) * )
164
+ $crate :: decode_slice!( input: $x, $( $spec) * )
299
165
} ;
300
166
}
301
167
#[ test]
0 commit comments