Open sharksforarms opened 4 years ago
A good first step would be to add bounds to DekuRead
& DekuWrite
for every type parameters in structures that derive those traits. The compiler would then indicate which specific field does not derive the proper traits.
Currently when a type does not derive the appropriate trait, an error is thrown because they're needed by the read
& write
functions, and the compiler points to the DekuRead
/DekuWrite
span in the derive
macro.
Hey @MrNbaYoh thanks for the suggestion!
Experimenting with the following, is this what you mean?
trait DekuRead {
}
impl DekuRead for u8 {
}
struct Test {
field_a: u8,
field_b: u16,
}
#[allow(non_camel_case_types)]
trait DekuContainerRead<field_a: DekuRead = u8, field_b: DekuRead = u16> {
}
impl DekuContainerRead for Test {
}
error[E0277]: the trait bound `u16: DekuRead` is not satisfied
--> examples/out.rs:14:58
|
14 | trait DekuContainerRead<field_a: DekuRead = u8, field_b: DekuRead = u16> {
| ---------------------------------------------------------^^^^^^^^-------
| | |
| | the trait `DekuRead` is not implemented for `u16`
| required by `DekuContainerRead`
error[E0277]: the trait bound `u16: DekuRead` is not satisfied
--> examples/out.rs:17:6
|
14 | trait DekuContainerRead<field_a: DekuRead = u8, field_b: DekuRead = u16> {
| -------- required by this bound in `DekuContainerRead`
...
17 | impl DekuContainerRead for Test {
| ^^^^^^^^^^^^^^^^^ the trait `DekuRead` is not implemented for `u16`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.
error: could not compile `deku`
I'm currently looking into how the Debug
derive works.... This is pretty much what you're describing I think
Actually, serde does something similar which is nice:
use serde::Serialize;
struct Test2 {}
#[derive(Serialize)]
struct Test {
field_a: u8,
field_b: Test2,
}
fn main() {
}
error[E0277]: the trait bound `Test2: Serialize` is not satisfied
--> src/main.rs:8:5
|
8 | field_b: Test2,
| ^^^^^^^ the trait `Serialize` is not implemented for `Test2`
|
= note: required by `_serde::ser::SerializeStruct::serialize_field`
error: aborting due to previous error
i.e.
For,
The error message is
Which, without knowledge of Deku internals, is not helping the user.
A better error message might be ". Did you mean
bits
not supported on Veccount
?"Task: impl missing contexts for types and give helpful error message as a panic!