There can only be one unsized field in a struct, and it must be the last one, even though Rust otherwise reserves the right to reorder fields. Move the declaration of id before the unsized lock and it will work.
You're right. The compiler should make this explicit. The reason as why this rule is true is not hard to conceive, however, this feature would be good for beginners
The last note in full error message does state this restriction:
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> src/lib.rs:2:5
|
2 | data: [u8],
| ^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `[u8]`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: only the last field of a struct may have a dynamically sized type
Maybe the error could be refined in this particular case, with only one unsized field but not the last.