Allow extra fields when using #[from] (using Default trait)

未关闭
#441 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
rust
领域
tooling

调研方向

首先检查 #[from] 的展开和生成的 From 实现,然后查看之前关于向错误添加上下文的 issue。当就带有默认值的额外字段或可选的 #[from] 参数所应采用的行为达成一致并完成实现,且不改变 crate 预期的简洁性时,工作就完成了。

由索引模型根据 Issue 内容生成。

描述

It would be useful to allow extra fields in the structs when using #[from], to optionally add additional context. I think that could be achieved by simply initializing them with Default::default() in the From implementation, and allowing user to add the context to errors later (e.g. with another derive macro from a different crate).

I could provide a PR that implement it, but I saw from some previous issues that you're somewhat against the idea of supporting adding context to the errors, so I want to make sure you're on board with this before I spend more time on it.

I believe that my proposal is minimally intrusive, and maintains the spirit of simplicity of this crate. If this would stray too much from the current interface, how about adding optional parameter to #[from], e.g. #[from(with_defaults)], that would trigger this behavior?

主要语言
Rust
星标
5.6k
派生
220
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

dtolnay/thiserror 的其他 Issue

查看 dtolnay/thiserror 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。