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
11
//! This library does not support no-std yet because it depends on a proc-macro library that depends
18
12
//! on data-encoding with std and cargo propagates that feature although it's a build dependency.
19
13
//! See https://github.com/rust-lang/cargo/issues/5730 for more information.
23
17
//! You can define a compile-time byte slice from an encoded string literal:
24
18
//!
25
19
//! ```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");
20
+ //! const HELLO_SLICE: &'static [u8] = &data_encoding_macro::hexlower!("68656c6c6f");
21
+ //! const FOOBAR_SLICE: &'static [u8] = &data_encoding_macro::base64!("Zm9vYmFy");
32
22
//! # fn main() {}
33
23
//! ```
34
24
//!
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:
25
+ //! You can also define a compile-time byte array from an encoded string literal:
37
26
//!
38
27
//! ```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");
28
+ //! data_encoding_macro::hexlower_array!("const HELLO" = "68656c6c6f");
29
+ //! data_encoding_macro::base64_array!("const FOOBAR" = "Zm9vYmFy");
44
30
//! # fn main() {}
45
31
//! ```
46
32
//!
47
33
//! You can define a compile-time custom encoding from its specification:
48
34
//!
49
35
//! ```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! {
36
+ //! const HEX: data_encoding::Encoding = data_encoding_macro::new_encoding! {
57
37
//! symbols: "0123456789abcdef",
58
38
//! translate_from: "ABCDEF",
59
39
//! translate_to: "abcdef",
60
40
//! };
61
- //! const BASE64: Encoding = new_encoding! {
41
+ //! const BASE64: data_encoding:: Encoding = data_encoding_macro:: new_encoding! {
62
42
//! symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
63
43
//! padding: '=',
64
44
//! };
72
52
//! [data-encoding]: https://crates.io/crates/data-encoding
73
53
//! [hexadecimal]: macro.hexlower_permissive.html
74
54
75
- #![ cfg_attr( not( feature = "stable" ) , feature( proc_macro_hygiene) ) ]
76
- #![ warn( unused_results) ]
77
55
#![ no_std]
56
+ #![ warn( unused_results) ]
78
57
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
58
#[ doc( hidden) ]
100
- pub use data_encoding_macro_internal:: internal_decode_slice;
59
+ pub use data_encoding_macro_internal:: {
60
+ internal_decode_array, internal_decode_slice, internal_new_encoding,
61
+ } ;
101
62
102
63
/// Defines a compile-time byte array by decoding a string literal
103
64
///
@@ -110,10 +71,7 @@ pub use data_encoding_macro_internal::internal_decode_slice;
110
71
/// # Examples
111
72
///
112
73
/// ```rust
113
- /// #[macro_use]
114
- /// extern crate data_encoding_macro;
115
- ///
116
- /// decode_array! {
74
+ /// data_encoding_macro::decode_array! {
117
75
/// name: "const OCTAL",
118
76
/// symbols: "01234567",
119
77
/// padding: '=',
@@ -123,7 +81,6 @@ pub use data_encoding_macro_internal::internal_decode_slice;
123
81
/// ```
124
82
///
125
83
/// [new_encoding]: macro.new_encoding.html
126
- #[ cfg( not( feature = "stable" ) ) ]
127
84
#[ macro_export]
128
85
macro_rules! decode_array {
129
86
( $( $arg: tt) * ) => {
@@ -141,11 +98,7 @@ macro_rules! decode_array {
141
98
/// # Examples
142
99
///
143
100
/// ```rust
144
- /// # #![feature(proc_macro_hygiene)]
145
- /// #[macro_use]
146
- /// extern crate data_encoding_macro;
147
- ///
148
- /// const OCTAL: &'static [u8] = &decode_slice! {
101
+ /// const OCTAL: &'static [u8] = &data_encoding_macro::decode_slice! {
149
102
/// symbols: "01234567",
150
103
/// padding: '=',
151
104
/// input: "237610==",
@@ -154,44 +107,13 @@ macro_rules! decode_array {
154
107
/// ```
155
108
///
156
109
/// [new_encoding]: macro.new_encoding.html
157
- #[ cfg( not( feature = "stable" ) ) ]
158
110
#[ macro_export]
159
111
macro_rules! decode_slice {
160
112
( $( $arg: tt) * ) => {
161
113
$crate:: internal_decode_slice!( $( $arg) * )
162
114
} ;
163
115
}
164
116
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
117
/// Defines a compile-time custom encoding
196
118
///
197
119
/// This macro takes a list of `key: value,` pairs (the last comma is required).
@@ -215,57 +137,7 @@ macro_rules! decode_slice {
215
137
/// # Examples
216
138
///
217
139
/// ```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! {
140
+ /// const HEX: data_encoding::Encoding = data_encoding_macro::new_encoding! {
269
141
/// symbols: "0123456789abcdef",
270
142
/// ignore: " \r\t\n",
271
143
/// wrap_width: 32,
@@ -275,27 +147,25 @@ macro_rules! new_encoding {
275
147
/// };
276
148
/// # fn main() {}
277
149
/// ```
278
- #[ cfg( feature = "stable" ) ]
279
150
#[ macro_export]
280
151
macro_rules! new_encoding {
281
152
( $( $arg: tt) * ) => {
282
- :: data_encoding:: Encoding :: internal_new( & internal_new_encoding!{ $( $arg) * } )
153
+ data_encoding:: Encoding :: internal_new( & $crate :: internal_new_encoding!{ $( $arg) * } )
283
154
} ;
284
155
}
285
156
286
157
macro_rules! make {
287
158
( $base: ident $base_array: ident = $ref: ident; $( $spec: tt) * ) => {
288
- #[ cfg( not( feature = "stable" ) ) ]
289
159
#[ macro_export]
290
160
macro_rules! $base_array {
291
161
( $n: tt = $x: tt) => {
292
- decode_array!( name: $n, input: $x, $( $spec) * ) ;
162
+ $crate :: decode_array!( name: $n, input: $x, $( $spec) * ) ;
293
163
} ;
294
164
}
295
165
#[ macro_export]
296
166
macro_rules! $base {
297
167
( $x: tt) => {
298
- decode_slice!( input: $x, $( $spec) * )
168
+ $crate :: decode_slice!( input: $x, $( $spec) * )
299
169
} ;
300
170
}
301
171
#[ test]
0 commit comments