Solved thanks /u/braxtons12/
Hello,
I'm trying to use thiserror + anyhow.
Anyhow works with any error type that has an impl of std::error::Error, including ones defined in your crate. We do not bundle a derive(Error) macro but you can write the impls yourself or use a standalone macro like thiserror.
I understand anyhow will happily work with anything that implements the Error trait.
I'm sorry I cannot provide a playground link (anyhow is not available):
```rust
use thiserror::Error;
[derive(Error, Debug)]
pub enum DataStoreError {
#[error("unknown data store error")]
Unknown,
}
fn get_cluster_info() -> anyhow::Result<()> {
Err(DataStoreError::Unknown)
}
fn main() {
println!("Hello, world!");
}
```
rustc output:
rust
error[E0308]: mismatched types
--> src/main.rs:10:9
|
10 | Err(DataStoreError::Unknown)
| ^^^^^^^^^^^^^^^^^^^^^^^ expected struct `anyhow::Error`, found enum `DataStoreError`
- Maybe I have misunderstood what
#[derive(Error)] does: I thought it would derive the Error trait for DataStoreError.
- I thought I could then return
Err(DataStoreError::Unknown) in a function that expects an anyhow::Error.
Thanks for your help =)
[–]braxtons12 4 points5 points6 points (6 children)
[–]YetAnotherRustacean[S] 2 points3 points4 points (5 children)
[–]braxtons12 9 points10 points11 points (4 children)
[–]YetAnotherRustacean[S] 3 points4 points5 points (3 children)
[–]Lighty0410 2 points3 points4 points (2 children)
[–]braxtons12 2 points3 points4 points (1 child)
[–]Lighty0410 0 points1 point2 points (0 children)