Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no_std use core::error::Error 1.81 stabilizes the Error trait in core #518

Open
zhang-wenchao opened this issue Nov 1, 2024 · 3 comments

Comments

@zhang-wenchao
Copy link

1.81 stabilizes the Error trait in core, allowing usage of the trait in #![no_std] libraries.

@zhang-wenchao
Copy link
Author

dtolnay/anyhow#389

@Dirbaio
Copy link
Member

Dirbaio commented Nov 1, 2024

can you expand on what types from this lib would you expect to implement core::error::Error? This is not very actionable otherwise.

@zhang-wenchao
Copy link
Author

I just want to simply use ? operator to propagate errors. Don't map_err.

use heapless::String;
use anyhow::Result;

pub fn test() -> Result<String<256>> {
    let mut phrase = String::new();
    phrase.push_str("XX")?;
    Ok(phrase)
}
the trait bound `(): core::error::Error` is not satisfied
the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>`
required for `anyhow::Error` to implement `From<()>`
required for `Result<String<256>, anyhow::Error>` to implement `FromResidual<Result<Infallible, ()>>`rustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic message [0]?0#file:///home/life/Develop/job/my/embedded/ohw-wallets/src/mnemonic.rs)
pub fn test() -> Result<String<256>> {
    let mut phrase = String::new();
    phrase.push_str("XX").map_err(|_| anyhow!(""))?;
    Ok(phrase)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants