oxidecomputer / oxidecomputer/typify
Q: Missing type and simplify generated code
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 898
- Forks
- 114
- Avg merge
- 4h 18m
- Merged PRs (30d)
- 14
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"], )
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.
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.
Assessment
- Tech stack
- cpp, rust
- Domain
- compilers, devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100