Very new to Rust here...
// begin somewhere in an external crate...
pub struct MyData<'a> {
something: &'a str,
}
impl<'a> MyData<'a> {
pub fn new(s: &'a str) -> Self {
MyData { something: s }
}
pub fn get_something(&self) -> &'a str {
self.something
}
}
// end somewhere in an external crate...
// ...somewhere in my code trying to create an instance...
pub fn get_my_data<'a>(data_piece: &'a str) -> MyData<'a> {
let full_data = format!("My data piece is here ->{}<-", data_piece);
MyData::new(&full_data)
}
Seems like a basic common pattern - collect some data, modify it somewhat, pass it to create an instance.
I do understand the problem!
The question is - what is the proper way to handle it?
Am I totally out of luck, because of how MyData is implemented?