Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Generate code which only compiles if type is invariant
I decided to make a library providing a macro to enforce a compile time requirement that a type's generic parameters conform to a certain variance. My plan for doing this was to have the macro generate code which only compiles if the type follows that variance, but I cannot figure out how to do that for invariance. Is making a function which only compiles if a type is invariant with respect to a specific generic parameter even possible? If not, would the best path forward be to insert fields to ensure invariance but continue with the compile-time checking strategy for enforcing covariance and contravariance?
2 posts - 2 participants
🏷️ rust_feed