Q: Missing type and simplify generated code
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reading my_struct.schema.json and my_struct.schema.rs.txt, then compare the generated output with the quicktype example in the issue. Determine how the generator currently represents the schema and what changes would be needed for a my_struct type and direct primitive types; done means the generated Rust matches those requested shapes.
Written by the indexing model from the issue text.
Description
I'm experimenting with code generation based on schemas generated by the glaze C++ library.
The following C++ struct
struct my_struct {
int i{};
double d{};
std::string hello{};
std::array<uint64_t, 3> arr{};
std::map<std::string, int> map{};
};
yields this schema:
And this is the generated rust code.
I was wondering the following:
- Apparently, there is no rust equivalent of
my_structbeing generated. Instead just for every type insidemy_struct. Is there maybe an issue with the schema? - Is it somehow possible to prevent generating wrapper types for types like
Doubleetc and just use equivalent types directly?
To demonstrate the latter: I pasted the schema to quicktype and the result seems quite idiomatic:
use serde::{Serialize, Deserialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MyStruct {
arr: Option<Vec<i64>>,
d: Option<f64>,
hello: Option<String>,
i: Option<i64>,
map: Option<HashMap<String, i64>>,
}
(note: one can get rid of generating all the values as Option by adding "required": ["arr", "d", "hello", "i", "map"], )
- Dominant language
- Rust
- Stars
- 898
- Forks
- 114
- Avg merge
- 4h 18m
- Merged PRs (30d)
- 14
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from oxidecomputer/typify
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
oxidecomputer/typify#1077 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
oxidecomputer/typify#1075 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 50/100
oxidecomputer/typify#1060 ·
-
Difficulty 5/5 Over a week Newbie friendliness 48/100
oxidecomputer/typify#1059 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
oxidecomputer/typify#1022 · 1 comment ·
All issues in oxidecomputer/typify
Similar issues
-
Browser (wasm) relay client cannot connect to relays whose URL has a trailing-dot FQDN hostname Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
n0-computer/iroh#4550 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
paritytech/zombienet-sdk#591 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
farion1231/cc-switch#7638 · 1 comment ·
-
onnx-ir re-exports ModelProto and GraphProto but not NodeProto, AttributeProto and AttributeType Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100