deku icon indicating copy to clipboard operation
deku copied to clipboard

Context cannot contain a reference

Open space-elephant opened this issue 2 years ago • 1 comments

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> {

space-elephant avatar Feb 01 '23 16:02 space-elephant

Can you provide a failing example?

sharksforarms avatar Feb 27 '23 14:02 sharksforarms