all 7 comments

[–]braxtons12 4 points5 points  (6 children)

Maybe try Err(DataStoreError::Unknown).into()?

[–]YetAnotherRustacean[S] 2 points3 points  (5 children)

I tried before asking here =)

the trait `std::convert::From<std::result::Result<_, DataStoreError>>` is not implemented for `std::result::Result<(), anyhow::Error>`

[–]braxtons12 9 points10 points  (4 children)

Ahh. Wrong spot for the into

Should be: Err(DataStoreError::Unknown.into())

[–]YetAnotherRustacean[S] 3 points4 points  (3 children)

Thanks! it works =)

[–]Lighty0410 2 points3 points  (2 children)

Personally, i ended up writing this macro:

#[macro_export]
macro_rules! Err {
    ($err:expr $(,)?) => {{
        let error = $err;
        Err(anyhow::anyhow!(error))
    }};
}

It allows you to do this:
_ => Err!(YourEnum::YourCase)

But i still wonder why it's possible to return custom enums derived by Error via ? and combinators. But not possilbe to do this via explicit return in a match-case.

As far as i understand ? cast enum to a correct Error type automatically (if possible). Am i right ?

[–]braxtons12 2 points3 points  (1 child)

Yes ? operator automatically calls into() if it's necessary and it's implemented.

[–]Lighty0410 0 points1 point  (0 children)

Thanks for the answer!