I'm very new to Rust and to get more familiar with the language I started to write a little ToDo program.
I've made a Struct corresponding to a Task :
struct Task {
id: int,
title: &'static str
}
And I tried to implement some methods to get directly the formatted line to write in a file :
impl Task {
fn to_string (&self) -> String {
let line = self.id.to_string() + "\t" + self.title;
line
}
fn to_str (&self) -> &str {
let line = self.to_string();
let formatted_str : &str = line.as_slice();
formatted_str
}
}
I get an error which says that 'line' does not live long enough. I've tried to add the lifetime information as it is explained here : http://rustbyexample.com/lifetime/fn.html but I've got the same error again.
Is there a solution to this situation ? I'm new to Rust so I probably missed something.
Thanks for your help !