Skip to content

Commit

Permalink
Fix pad_* attributes in no_std (#478)
Browse files Browse the repository at this point in the history
* Fix cannot find macro vec in this scope when using no_std
  • Loading branch information
wcampbell0x2a committed Sep 8, 2024
1 parent 1345a72 commit 0acc87a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions deku-derive/src/macros/deku_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ fn emit_padding(bit_size: &TokenStream) -> TokenStream {

if (__deku_pad % 8) == 0 {
let bytes_read = __deku_pad / 8;
let mut buf = vec![0; bytes_read];
let mut buf = alloc::vec![0; bytes_read];
let _ = __deku_reader.read_bytes(bytes_read, &mut buf)?;
} else {
let _ = __deku_reader.read_bits(__deku_pad)?;
Expand All @@ -610,7 +610,7 @@ fn emit_padding_bytes(bit_size: &TokenStream) -> TokenStream {
)?;


let mut buf = vec![0; __deku_pad];
let mut buf = alloc::vec![0; __deku_pad];
let _ = __deku_reader.read_bytes(__deku_pad, &mut buf)?;
}
}
Expand Down
4 changes: 2 additions & 2 deletions ensure_no_std/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct DekuTest {
#[deku(bits = 3)]
field_b: u8,
count: u8,
#[deku(count = "count")]
#[deku(count = "count", pad_bytes_after = "8")]
data: Vec<u8>,
}

Expand All @@ -39,7 +39,7 @@ fn main() -> ! {
// now the allocator is ready types like Box, Vec can be used.

#[allow(clippy::unusual_byte_groupings)]
let test_data: &[u8] = &[0b10101_101, 0x02, 0xBE, 0xEF];
let test_data: &[u8] = &[0b10101_101, 0x02, 0xBE, 0xEF, 0xff];
let mut cursor = deku::no_std_io::Cursor::new(test_data);

// Test reading
Expand Down

0 comments on commit 0acc87a

Please sign in to comment.