defref a lifetime value from a none lifetime value

  Kiến thức lập trình

Can I write some code to get a lifetime value deref from a none lifetime value ?


struct A {
 x: String,
}

struct B<'a> {
 y: &<'a> str,
}

impl Deref for A {
  type Target = B;
  fn deref(&self) -> &Self::Target {
    &B{y: &self.x}
  }
}

New contributor

Bayou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

LEAVE A COMMENT