This repository was archived by the owner on Aug 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
This repository was archived by the owner on Aug 15, 2025. It is now read-only.
bincode_derive does not like generic parameters with defaults #763
Copy link
Copy link
Open
Description
I'm trying to add bincode to musli benchmarks, and I want to derive Decode
on something like the following:
use bincode::Decode;
#[derive(Decode)]
pub struct Mesh<V: AsRef<[Triangle]> = Vec<Triangle>> {
pub triangles: V,
}
#[derive(Decode)]
struct Triangle {
x: u32,
y: u32,
z: u32,
}
I see this:
Compile errors
error: generic parameters with a default must be trailing
--> tests/examples/bincode-derive.rs:4:17
|
4 | pub struct Mesh<V: AsRef<[Triangle]> = Vec<Triangle>> {
| ^
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
--> tests/examples/bincode-derive.rs:4:17
|
4 | pub struct Mesh<V: AsRef<[Triangle]> = Vec<Triangle>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
= note: `#[deny(invalid_type_param_default)]` on by default
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
--> tests/examples/bincode-derive.rs:4:17
|
4 | pub struct Mesh<V: AsRef<[Triangle]> = Vec<Triangle>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
error: could not compile `tests` (example "bincode-derive") due to 5 previous errors
In my mind, it should be possible to derive this, all though ultimately the Decode
implementation would have to be conditional on implementing Decode
, either implicitly or explicitly with bounds parameters.
Reference: udoprog/musli#266