Allow using `enum`s in form easily

Open
#356 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
rust
Domain
backend

Research direction

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.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Rust
Stars
1.1k
Forks
57
Avg merge
17h 39m
Merged PRs (30d)
12

Getting set up

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 cot-rs/cot

All issues in cot-rs/cot

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.