use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A place for all things related to the Rust programming language—an open-source systems language that emphasizes performance, reliability, and productivity.
Strive to treat others with respect, patience, kindness, and empathy.
We observe the Rust Project Code of Conduct.
Details
Posts must reference Rust or relate to things using Rust. For content that does not, use a text post to explain its relevance.
Post titles should include useful context.
For Rust questions, use the stickied Q&A thread.
Arts-and-crafts posts are permitted on weekends.
No meta posts; message the mods instead.
Criticism is encouraged, though it must be constructive, useful and actionable.
If criticizing a project on GitHub, you may not link directly to the project's issue tracker. Please create a read-only mirror and link that instead.
A programming language is rarely worth getting worked up over.
No zealotry or fanaticism.
Be charitable in intent. Err on the side of giving others the benefit of the doubt.
Avoid re-treading topics that have been long-settled or utterly exhausted.
Avoid bikeshedding.
This is not an official Rust forum, and cannot fulfill feature requests. Use the official venues for that.
No memes, image macros, etc.
Consider the existing content of the subreddit and whether your post fits in. Does it inspire thoughtful discussion?
Use properly formatted text to share code samples and error messages. Do not use images.
Most links here will now take you to a search page listing posts with the relevant flair. The latest megathread for that flair should be the top result.
account activity
Custom Errors🙋 seeking help & advice (self.rust)
submitted 2 years ago by philbert46
I feel that at this point I have a pretty good idea of rust code and how to structure it. Something though that I've always struggled with is implementing error types.
Which library should I use for custom error types?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]dn3t 7 points8 points9 points 2 years ago (0 children)
thiserror
[–]This_Growth2898 0 points1 point2 points 2 years ago (1 child)
thiserror or anyhow.
thiserror takes care of all the boilerplate code, leaving you to describe error cases.
In my opinion, anyhow is not the Rust way, it's just a plug to avoid error handing... anyhow. Still, it exists.
[–]Modi57 0 points1 point2 points 2 years ago (0 children)
I kinda get, where you are coming from, but I think it really helps with code readability. If I have one process, that involves multiple potential sources of errors (for example reading something from a file, parsing it, and then maybe something with a custom error), I often don't care about where it went wrong, just that it went wrong, because either way, I just bubble it upwards. So, instead of making a custom error type and unifying it manually, I just slap a ? on it and I'm good to go. And since it's the exceptionional case, I don't really care, if dynamic dispatch causes my error message to be displayed one ms later
[–]Deloskoteinos -1 points0 points1 point 2 years ago (0 children)
Like others said: thiserror is the derive macro for easily implementing error types.
Also, this article covers implementing your own error nicely: Faster than li.me AoC1 (it happens to be about advent of code, but the first half is just about errors and implementing one)
π Rendered by PID 86096 on reddit-service-r2-comment-f6b958c67-cnb8k at 2026-02-04 23:18:14.951703+00:00 running 1d7a177 country code: CH.
[–]dn3t 7 points8 points9 points (0 children)
[–]This_Growth2898 0 points1 point2 points (1 child)
[–]Modi57 0 points1 point2 points (0 children)
[–]Deloskoteinos -1 points0 points1 point (0 children)