nvzqz / static-assertions

Ensure correct assumptions about constants, types, and more in Rust
https://docs.rs/static_assertions
Apache License 2.0
579 stars 23 forks source link

assert_impl_all! with serde::Deserialize #30

Open SOF3 opened 5 years ago

SOF3 commented 5 years ago

serde::Deserialize takes the lifetime parameter <'de>. How should I check that a class derives serde::Deserialize?

One of the working solutions is assert_impl_all!(MyType : serde::Deserialize<'static>);, using the trick that 'static is available everywhere. However, is this the best practice?

Please consider adding this note to the documentation.

Nadrieril commented 5 years ago

If/when https://github.com/nvzqz/static-assertions-rs/pull/28 gets accepted, I believe the following would work:

assert_impl!(for('a) MyType : serde::Deserialize<'a>);

In the meantime, I think using 'static is indeed the best we can do.