Skip to content

Conversation

@wcampbell0x2a
Copy link
Collaborator

@wcampbell0x2a wcampbell0x2a commented Jun 7, 2025

  • Return an empty vec when instructed to read to end or certain bytes
    but the struct is a ZST

    NOTE: I tried to solve this using const assertions, but quickly ran into the following. I think you could fix it with unsafe? But not very sure about that solution.

error[E0401]: can't use generic parameters from outer item
  --> src/impls/vec.rs:73:34
   |
72 | const fn assert_not_zst<T>() {
   |                         - type parameter from outer item
73 |     const_assert!(mem::size_of::<T>() > 0);
   |                                  ^ use of generic parameter from outer item
   |
   = note: a `const` is a separate item from the item that contains it

Closes #513

* Return an empty vec when instructed to read to end or certain bytes
  but the struct is a ZST
@github-actions
Copy link
Contributor

github-actions bot commented Jun 7, 2025

Benchmark for 075306a

Click to view benchmark
Test Base PR %
count_from_u8_specialize 99.6±0.59ns 99.8±0.81ns +0.20%
count_no_specialize 1867.9±19.04ns 1848.5±20.38ns -1.04%
count_specialize 98.5±1.06ns 102.0±1.14ns +3.55%
deku_read_bits 1230.8±14.11ns 1253.7±16.45ns +1.86%
deku_read_byte 5.6±0.06ns 5.6±0.04ns 0.00%
deku_read_enum 4.2±0.05ns 4.1±0.03ns -2.38%
deku_read_vec 30.7±0.36ns 30.6±0.47ns -0.33%
deku_write_bits 240.4±4.02ns 228.4±4.86ns -4.99%
deku_write_byte 24.0±0.34ns 24.3±0.34ns +1.25%
deku_write_enum 22.8±0.35ns 23.1±0.30ns +1.32%
deku_write_vec 437.9±5.96ns 453.9±4.86ns +3.65%
read_all 4.4±0.03µs 4.3±0.06µs -2.27%
read_all_bytes 4.3±0.06µs 4.3±0.06µs 0.00%

@wcampbell0x2a wcampbell0x2a changed the title chore: added test from issue 564 (failing) Return empty Vec on ZST Jun 7, 2025
@wcampbell0x2a wcampbell0x2a merged commit 90febe2 into master Jun 9, 2025
15 checks passed
@wcampbell0x2a wcampbell0x2a deleted the 513-return-empty-vec-for-zst branch June 9, 2025 23:20
@github-actions github-actions bot mentioned this pull request Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty structs cause an infinite loop when reading a Vec

3 participants