Support existing types with custom conversions
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 30/100
Rechercherichtung
Beginne mit dem rustdoc von import_types! und dem build.rs-Beispiel in den typify-Quellen. Vergleiche das dokumentierte Verhalten von with_conversion und with_replacement, einschließlich ihrer Kombinationen, und verfolge, wie generierte Felder serde-Attribute erhalten. Done sollte ein vorhandenes std::time::Duration-Feld mit benutzerdefinierter String-Konvertierung unterstützen, ohne schema-spezifische Rust-Typen zu erfordern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
I'm trying to use fields of type std::time::Duration and initialize them with strings like "500 ms". It doesn't appear to be possible right now.
I converted my code to build.rs so I can explore all documented functions. The import_types! documentation is unclear and insufficient. Actually, there is no example of build.rs in the rustdoc documentation, but I found an example in the typify sources.
Only with_replacement lets me replace a generated type with the existing one (std::time::Duration). The documentation for with_conversion appears to promise that behavior, but a new type is always generated. Combinations of with_replacement and other with_* don't seem to work.
Unfortunately, with_replacement doesn't let me specify custom serde for the field. Look e.g. for #[serde(with = "humantime_serde")] at https://docs.rs/humantime-serde/1.1.1/humantime_serde/ - it's specified on the field, not on the whole struct.
I tried some things with x-rust-type without any success. In any case, I don't see it as a clean approach. It should be possible for the schema to be Rust-agnostic and still support readable strings for duration.
Likewise, I don't want to use numbers for duration. It's too easy to confuse seconds with milliseconds.
Currently supported formats ("uuid", "date", "ip" etc) all support conversion from string. The problem with std::time::Duration is that it's standard (i.e. many std functions use it) but cannot be constructed from a string. So a different mechanism is needed.
- Vorherrschende Sprache
- Rust
- Sterne
- 898
- Forks
- 114
- Ø Merge
- 4 Std. 18 Min.
- Gemergte PRs (30 T.)
- 14
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus oxidecomputer/typify
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
oxidecomputer/typify#1077 ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
oxidecomputer/typify#1075 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 50/100
oxidecomputer/typify#1060 ·
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 48/100
oxidecomputer/typify#1059 ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 65/100
oxidecomputer/typify#1022 · 1 Kommentar ·
Alle Issues in oxidecomputer/typify
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100