How to propagte an error from update function #963
Answered
by
90-008
d-mceneaney
asked this question in
Q&A
-
|
Hi, Is it not possible to propagate an error from the update function or am I doing something wrong? Thanks. fn update(&mut self, message: Message) -> Result<(), Box<dyn Error>> { //error expected trait, found enum Error, not a trait
match message {
Message::InputButtonPressed => {
let path = FileDialog::new()
.set_location("~/")
.add_filter("File", &["txt"])
.show_open_single_file()?; //error propagated here
}
}
Ok(())
} |
Beta Was this translation helpful? Give feedback.
Answered by
90-008
Jul 24, 2021
Replies: 1 comment 3 replies
-
|
You can't return a result from the update function, but what you can do is store the error as part of your application state. So something like: struct App {
last_result: Result<(), Error>,
}
impl Sandbox for App {
fn update(&mut self, message: Message) {
match message {
Message::Something => {
let result = do_something();
if result.is_err() {
self.last_result = result;
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
d-mceneaney
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can't return a result from the update function, but what you can do is store the error as part of your application state. So something like: