sharksforarms / deku

Declarative binary reading and writing: bit-level, symmetric, serialization/deserialization
Apache License 2.0
1.14k stars 55 forks source link

Context cannot contain a reference #319

Open space-elephant opened 1 year ago

space-elephant commented 1 year ago

When I use a reference in the context, it doesn't have the right lifetime.

error[E0106]: missing lifetime specifier
   --> src/main.rs:371:10
    |
371 | #[derive(DekuRead, DekuWrite)]
    |          ^^^^^^^^ expected named lifetime parameter
    |
    = help: this function's return type contains a borrowed value, but the signature does not say which one of `__deku_input_bits`'s 2 lifetimes it is borrowed from
    = note: this error originates in the derive macro `DekuRead` (in Nightly builds, run with -Z macro-backtrace for more info)

Could this be fixed by not using lifetime elision in deku_read? Something like this?

            fn read<'a>(__deku_input_bits: &'a #lifetime ::#crate_::bitvec::BitSlice<u8, ::#crate_::bitvec::Msb0>, #ctx_arg) -> Result<(&'a #lifetime ::#crate_::bitvec::BitSlice<u8, ::#crate_::bitvec::Msb0>, Self), ::#crate_::DekuError> {
sharksforarms commented 1 year ago

Can you provide a failing example?