Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: OwningRef for arbitrary GATs?
Suppose I have a trait like
trait Foo {
type Bar<'a> where Self: 'a;
fn barify(&self) -> Self::Bar<'_>;
}
Is it possible to have some equivalent to the owning_ref crate where one can package together a F: Foo
with an F::Bar<'a>
that borrows from it? One option would be to create a struct like
struct FooAndItsBar<F>
where F: Foo
{
foo: Pin<Box<F>>,
bar: F::Bar<'static>,
}
and carefully use mem::transmute
to lengthen/shorten bar
s lifetime, however, this would require F: 'static
(although I guess this implicitly assumes that the representation of F::Bar<'a>
is identical regardless of 'a
. Is that sound, at least pending specialization?)
Is there any way to do this that doesn't impose an F: 'static
bound? Or is this unsound in principle?
3 posts - 3 participants
🏷️ Rust_feed