0

I'm trying to return the result of a format! after pattern matching an enum:

enum Enm {
    Cont(String)
}

fn call(enm: &Enm) -> &str {
    match *enm {
        Enm::Cont(ref s) => &format!("{}", s)
    }
}

fn main() {

}

But this won't work: borrowed value does not live long enough

How can I solve this?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
dragostis
  • 2,574
  • 2
  • 20
  • 39
  • @Shepmaster I need this for `fn description(&self) -> &str` in the Error trait. – dragostis Feb 25 '16 at 17:57
  • 1
    I understand, but that doesn't change the fact that you cannot do it (for all the reasons in the duplicate). Perhaps you'd also be interested in http://stackoverflow.com/q/29781331/155423. – Shepmaster Feb 25 '16 at 18:01

0 Answers0