Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't derive on structs containing Vec<T> #8

Closed
alecmocatta opened this issue Oct 30, 2020 · 2 comments
Closed

Can't derive on structs containing Vec<T> #8

alecmocatta opened this issue Oct 30, 2020 · 2 comments

Comments

@alecmocatta
Copy link

This example fails:

use speedy::{Readable, Writable};

#[derive(Readable, Writable)]
struct Wrap<T>(Vec<T>);

with:

error[E0277]: the trait bound `T: Readable<'a_, C_>` is not satisfied
 --> common/src/lib.rs:8:10
  |
8 | #[derive(Readable, Writable)]
  |          ^^^^^^^^ the trait `Readable<'a_, C_>` is not implemented for `T`
  |
  = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `T`
  |
8 | #[derive(Readable, T: Readable<'a_, C_>, Writable)]
  |                  ^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `T: Writable<C_>` is not satisfied
 --> common/src/lib.rs:8:20
  |
8 | #[derive(Readable, Writable)]
  |                    ^^^^^^^^ the trait `Writable<C_>` is not implemented for `T`
  |
  = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `T`
  |
8 | #[derive(Readable, Writable, T: Writable<C_>)]
  |                            ^^^^^^^^^^^^^^^^^

The expanded code looks fine, I think this is a Rust issue. rust-lang/rust#20671 and rust-lang/rust#44491 look relevant.

I've worked around this by manually impling these traits. A nicer solution might be enabling a bound attribute, akin to serde's?

@alecmocatta alecmocatta changed the title Can't derive on structs containing Foo<T> Can't derive on structs containing Vec<T> Oct 30, 2020
@koute
Copy link
Owner

koute commented Oct 31, 2020

Thanks. Should be fixed in 0.7.1.

@koute koute closed this as completed Oct 31, 2020
@alecmocatta
Copy link
Author

Confirmed. Thanks for the useful project and swift fix @koute!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants