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 1.82 use anyhow #389

Closed
zhang-wenchao opened this issue Oct 30, 2024 · 4 comments
Closed

no_std 1.82 use anyhow #389

zhang-wenchao opened this issue Oct 30, 2024 · 4 comments

Comments

@zhang-wenchao
Copy link

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

pub fn test() -> Result<String<256>> {
    let mut phrase = String::new();
    phrase.push_str("XX")?;
    Ok(phrase)
}
   --> src/mnemonic.rs:310:26
    |
310 |     phrase.push_str("XX")?;
    |                          ^ the trait `core::error::Error` is not implemented for `()`, which is required by `Result<String<256>, anyhow::Error>: FromResidual<Result<Infallible, ()>>`
    |
    = help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>`
    = note: required for `anyhow::Error` to implement `From<()>`
    = note: required for `Result<String<256>, anyhow::Error>` to implement `FromResidual<Result<Infallible, ()>>`

I see the document say that it can be used directly by 1.81 or more? Is there any problem with my understanding?

@dtolnay
Copy link
Owner

dtolnay commented Oct 30, 2024

What error message are you expecting test to return if the push_str fails?

@zhang-wenchao
Copy link
Author

I actually do n’t pay attention to the wrong content. I can use it directly? Symbols are the best, I do so now.

pub fn test() -> Result<String<256>> {
    let mut phrase = String::new();
    phrase.push_str("XX").map_err(|_| anyhow!(""))?;
    Ok(phrase)
}

I use a translator, there may be errors in grammar. I hope you can understand and thank you very much.

@zhang-wenchao
Copy link
Author

I notice that in the new version I can avoid using map_err. Am I understanding this incorrectly.

@zhang-wenchao
Copy link
Author

It seems that core::error::Error cannot use the ? symbol directly.

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