Improve #[from] documentation example.

Open Beginner friendly
#135 4 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
62/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale
Tech stack
rust
Domain
documentation

Research direction

Start by reading the library documentation examples for the #[from] attribute, especially the tuple and struct-field forms shown in the issue. Update the documentation to demonstrate displaying the derived io::Error message, and consider the work done when the example makes that behavior clear.

Written by the indexing model from the issue text.

Description

Hey folks,

There is an issue that took me a while to understand, and it's that in the lib doc is not very clear how to display the error that is being derived with #[from] macro.

The actual example is e.g.

    #[error("data store disconnected")]
    Disconnect(#[from] io::Error)

Despite there is also an example of how to use from attribute over a struct field e.g.

#[derive(Error, Debug)]
pub enum MyError {
    Io {
        #[from]
        source: io::Error,
        backtrace: Backtrace,
    },
}

None of these examples tells you can do it e.g.

    #[error("data store disconnected: {0}")]
    Disconnect(#[from] io::Error)

Would be great to have it in the doc.

Thanks!

Dominant language
Rust
Stars
5.5k
Forks
214
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dtolnay/thiserror

All issues in dtolnay/thiserror

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.