These two code snippets show two different usages of ctx. However, the latter works fine, while the former fails to build.
error[E0277]: the trait bound `&mut HashMap<String, u8>: std::marker::Copy` is not satisfied
--> src/core.rs:15:20
|
15 | pub questions: Vec<DnsQuestion>,
| ^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `&mut HashMap<String, u8>`, which is required by `Vec<core::DnsQuestion>: deku::DekuReader<'_, _>`
|
= help: the following other types implement trait `deku::DekuReader<'a, Ctx>`:
`Vec<T>` implements `deku::DekuReader<'a, (Limit<T, Predicate>, Ctx)>`
`Vec<T>` implements `deku::DekuReader<'a, Limit<T, Predicate>>`
= note: `std::marker::Copy` is implemented for `&HashMap<String, u8>`, but not for `&mut HashMap<String, u8>`
= note: required for `Vec<core::DnsQuestion>` to implement `deku::DekuReader<'_, (Limit<core::DnsQuestion, _>, &mut HashMap<String, u8>)>`
The former approach doesn't require adding a reader and writer. So, if ctx is mutable instead of using the Copy trait, it allows for writing simpler and more straightforward code.
These two code snippets show two different usages of
ctx
. However, the latter works fine, while the former fails to build.The former approach doesn't require adding a
reader
andwriter
. So, ifctx
is mutable instead of using theCopy
trait, it allows for writing simpler and more straightforward code.