Skip to content

Instantly share code, notes, and snippets.

@mheiber
Created January 9, 2022 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mheiber/ae5751cced189ddd532b740ef725b644 to your computer and use it in GitHub Desktop.
Save mheiber/ae5751cced189ddd532b740ef725b644 to your computer and use it in GitHub Desktop.
hrtb
trait A {}
struct SasA{}
impl A for SasA {}
trait Db<'d> {
type Mem: ?Sized + A + 'd;
fn d(&self) -> &Self::Mem;
}
trait Trait: for<'d> Db<'d> {
}
struct D {
}
impl<'d> Db<'d> for D {
type Mem = dyn A + 'd;
fn d(&self) -> &Self::Mem {
Box::leak(Box::new(SasA{}))
}
}
fn main() {
let d = D{};
<D as Db>::d(&d);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment