Skip to content

Commit 0f7121f

Browse files
committed
tweak parse_into_structs
1 parent ce70516 commit 0f7121f

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

blobby/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ assert_eq!(SLICE.len(), 8);
2929
3030
blobby::parse_into_structs!(
3131
BLOBBY_DATA;
32-
static ITEMS;
33-
struct Foo { a, b, c, d }
32+
#[define_struct]
33+
static ITEMS: &[Item { a, b, c, d }];
3434
);
3535
3636
assert_eq!(
3737
ITEMS[0],
38-
Foo {
38+
Item {
3939
a: b"hello",
4040
b: b" ",
4141
c: b"",
@@ -44,7 +44,7 @@ assert_eq!(
4444
);
4545
assert_eq!(
4646
ITEMS[1],
47-
Foo {
47+
Item {
4848
a: b":::",
4949
b: b"world!",
5050
c: b"hello",

blobby/src/decode.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ macro_rules! parse_into_slice {
215215
macro_rules! parse_into_structs {
216216
(
217217
$data:expr;
218-
$static_vis:vis static $items_name:ident;
219-
$ty_vis:vis struct $item:ident {
220-
$($field:ident),* $(,)?
221-
}
218+
#[define_struct]
219+
$static_vis:vis static $items_name:ident: &[
220+
$ty_vis:vis $item:ident { $($field:ident),* $(,)? }
221+
];
222222
) => {
223223
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
224224
$ty_vis struct $item {
@@ -227,19 +227,17 @@ macro_rules! parse_into_structs {
227227

228228
$crate::parse_into_structs!(
229229
$data;
230-
$static_vis static $items_name;
231-
existing struct $item {
232-
$($field),*
233-
}
230+
$static_vis static $items_name: &[
231+
$item { $($field),* }
232+
];
234233
);
235234
};
236235

237236
(
238237
$data:expr;
239-
$static_vis:vis static $items_name:ident;
240-
existing struct $item:ident {
241-
$($field:ident),* $(,)?
242-
}
238+
$static_vis:vis static $items_name:ident: &[
239+
$item:ident { $($field:ident),* $(,)? }
240+
];
243241
) => {
244242
$static_vis static $items_name: &[$item] = {
245243
const RAW_ITEMS: &[&[u8]] = $crate::parse_into_slice!($data);

0 commit comments

Comments
 (0)