support enums whose unit variants serialize as something other than strings

Đang mở
#43 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
json, rust
Lĩnh vực
backend, devtools

Hướng nghiên cứu

Start by reading how typespace represents enums and generates serialization code; the issue does not name specific files or tests. Trace how enum variants are represented and how generated code handles serde serialization and deserialization, then check the related Display and FromStr behavior. Done means typespace can represent variants serialized as arbitrary JSON values and generate the corresponding implementations.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

A schema like

{ "enum": [true, 1, "on"] }

has no representation in typespace today: an enum's unit variants serialize under their (renamed) Rust names, which are strings.

This isn't something serde annotations can express. External tagging is the only serde scheme that requires a unit variant's serialized value to be a string, and it's serde's default because it's the cheapest to deserialize; the other tagging forms don't help with a bare true or 1. So this takes two steps: typespace has to be able to represent a variant whose serialized form is an arbitrary JSON value, and then it has to generate Serialize and Deserialize impls for it.

Rather than treating these enums as special, my inclination is to generate the serde impls for all enums (or maybe all types). The argument for deriving is weaker than it looks: serde annotations don't appear in the docs, so the "familiar notation" benefit only reaches someone reading the generated source, and we already spend about as much effort organizing our structures to emit the right annotations as we would generating the impls directly.

Related: Display and FromStr for such an enum are the same gap seen from the other side, and should close with this.

Ngôn ngữ chính
Rust
Star
4
Fork
4
Merge trung bình
15 giờ 16 phút
Pull request đã merge (30 ngày)
26

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của oxidecomputer/typespace

Tất cả issue của oxidecomputer/typespace

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.