Last active
August 1, 2020 16:33
-
-
Save kilroyjones/90880fb2c13c3af1db11f8a87266cb78 to your computer and use it in GitHub Desktop.
Issue with errors and async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//In using the automate library which is an async library that talks to rust I had two | |
//different errors I needed to deal with. One was automate::Error and the other was | |
//Box<dyn std::error::Error> from a call to an API in a module I'd created. | |
//Automate: https://crates.io/crates/automate | |
//mycode.rs | |
async fn weather(ctx: &mut Context, data: &MessageCreateDispatch) -> Result<(), Error> { | |
... | |
if cmd == "!w" { | |
let temp = get_weather(&msg.content[2..]).await?; | |
... | |
//Error happened on line 12 stating: | |
the trait `std::convert::From<std::boxed::Box<dyn std::error::Error>>` is not implemented for `automate::Error` | |
//I tried to add it to mycode.rs and got this: | |
impl doesn't use only types from inside the current crate | |
//So instead I added it to automate's errors.rs file and it compiles | |
impl From<std::boxed::Box<dyn std::error::Error>> for Error { | |
fn from(err: std::boxed::Box<dyn std::error::Error>) -> Self { | |
Error::new(err.to_string()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment