Idiomatic way to have a ZST that is covariant in all lifetime parameters

⚓ Rust    📅 2025-06-03    👤 surdeus    👁️ 3      

surdeus

Warning

This post was published 63 days ago. The information described in this article may have changed.

Currently when I have a type constructor that is based purely on lifetime parameters and for which is a ZST and for which I'd like the type to be covariant in all the lifetime parameters, I define something like below:

struct Foo<'a, 'b, 'c>(PhantomData<fn() -> (&'a (), &'b (), &'c ())>);

As the quantity of lifetime parameters grows, this gets quite unwieldy. Admittedly I use this almost exclusively in internal code and further when wanting to define a "visitor" for something like serde::de::Visitor, so it's not that big of a deal. Is there something more concise that allows me to treat each lifetime parameter independently (e.g., &'a &'b &'c () would not suffice since that implies 'c: 'b + 'a, 'b: 'a), is Send + Sync, and does not signal to the compiler that the type actually owns anything?

2 posts - 2 participants

Read full topic

🏷️ rust_feed