HackerTrans
热门最新趋势评论往期问答秀出招聘

shepmaster

no profile record

提交

Why Castrol Honda Superbike crashes on (most) modern systems

seri.tools
176 分·作者 shepmaster·8个月前·35 评论

评论

shepmaster
·2个月前·讨论
At a Pittsburgher, I assumed it was a misspelling of “nebby”.

https://www.urbandictionary.com/define.php?term=Nebby
shepmaster
·8个月前·讨论
> But it's not natural to do so.

I tend to write most of my async Rust following the actor model and I find it natural. Alice Rhyl, a prominent Tokio contributor, has written about the specific patterns:

https://ryhl.io/blog/actors-with-tokio/
shepmaster
·10个月前·讨论
An official post about this is at

https://blog.rust-lang.org/2025/09/12/crates-io-phishing-cam...
shepmaster
·去年·讨论
You are quite welcome; thanks for the kind words!
shepmaster
·去年·讨论
You certainly can use thiserror to accomplish the same goals! However, your example does a little subtle slight-of-hand that you probably didn't mean to and leaves off the enum name (or the `use` statement):

    low_level_result.context(ErrorWithContextSnafu { context })?;
    low_level_result.map_err(|err| CustomError::ErrorWithContext { err, context })?;
Other small details:

- You don't need to move the inner error yourself.

- You don't need to use a closure, which saves a few characters. This is even true in cases where you have a reference and want to store the owned value in the error:

    #[derive(Debug, Snafu)]
    struct DemoError { source: std::io::Error, filename: PathBuf }

    let filename: &Path = todo!();
    result.context(OpenFileSnafu { filename })?; // `context` will change `&Path` to `PathBuf`
- You can choose to capture certain values implicitly, such as a source file location, a backtrace, or your own custom data (the current time, a global-ish request ID, etc.)

----

As an aside:

    #[error("failed to open a: {0}")]
It is now discouraged to include the text of the inner error in the `Display` of the wrapping error. Including it leads to duplicated data when printing out chains of errors in a nicer / structured manner. SNAFU has a few types that work to undo this duplication, but it's better to avoid it in the first place.
shepmaster
·去年·讨论
In addition to the sibling comment mentioning thiserror, I also submit my crate SNAFU (linked in my ancestor comment). Reducing some of the boilerplate is a big reason I enjoy using it.
shepmaster
·去年·讨论
> I create one error type per function/action

I do too! I've been debating whether I should update SNAFU's philosophy page [1] to mention this explicitly, and I think your comment is the one that put me over the edge for "yes" (along with a few child comments). Right now, it simply says "error types that are scoped to that module", but I no longer think that's strong enough.

[1]: https://docs.rs/snafu/latest/snafu/guide/philosophy/index.ht...
shepmaster
·去年·讨论
Thanks for using SNAFU! Any feedback you'd like to share?