Hi everybody
I am confused with traits in Rust (mostly because I came from Java).
I face a problem, and searches show me to use 'Box', but it does not change the error...
Here the code :
pub trait Presenter {
fn success(&mut self, message: dyn OutputMessage);
fn error(&mut self, message: dyn OutputMessage, error: Box<dyn Error>);
}
pub struct LibraryElementPresenter {
view_model: Option<LibraryElementViewModel>,
}
impl Presenter for LibraryElementPresenter {
fn success(&mut self, message: AddLibraryElementOutputMessage) {
self.view_model = Some(LibraryElementViewModel::new(message.get_library_element, None));
}
fn error(&mut self, message: AddLibraryElementOutputMessage, error: Box<dyn Error>) {
self.view_model = Some(LibraryElementViewModel::new(message.get_library_element, Some(error)));
}
}
With this code, I get the error : "expected trait object dyn OutputMessage
, found struct AddLibraryElementOutputMessage
"
In fact, I understand the error, but I don't know how to correct it. Box does not change anything.
And I don't want to use generic, because it could bring complexity in the software architecture that I try to implement (clean architecture).
Have you any idea to correct this please ?