Allow using `enum`s in form easily

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
停滞
技术栈
rust
领域
backend

调研方向

Read the existing Weekday implementation in cot/src/form/fields/chrono.rs and the SelectChoice work from issue #351. The issue leaves the design unresolved between a derive macro and wrapper structs, so first review the discussion and settle the API direction with maintainers; done means user-defined enums can be used as form fields, including the intended multiple-choice types.

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

描述

enhancement good first issue

Now with #351 merged, we have an easy way to derive SelectChoice for user-defined enums. However, its usefulness is quite limited, as there is still no obvious way to use them in forms, because they do not implement AsFormField.

For Weekday, we implement AsFormField manually:

https://github.com/cot-rs/cot/blob/144a377acb646852cbdf8a4b2c174b130003ecef/cot/src/form/fields/chrono.rs#L8-L54

For user-defined enums, I think there are two possible ways to tackle this:

  1. Add a derive macro that would create generic AsFormField impls for the enum as well as Vec<T>, HashSet<T>, etc., similarly to the ones for Weekday.
  2. Add wrapper structs (e.g. Choice and ChoiceMultiple) that would contain the enum implementing SelectChoice, and a Vec of these, respectively.

Which of these would be more appropriate is subject to discussion.

主要语言
Rust
星标
1.1k
派生
57
平均合并
17 小时 39 分钟
30 天内合并 PR
12

环境准备

从这里开始

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

cot-rs/cot 的其他 Issue

查看 cot-rs/cot 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

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