oxidecomputer / oxidecomputer/typify

Describe proper use of constrained types in their doc comments

Open
#451 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
898
Forks
114
Avg merge
4h 18m
Merged PRs (30d)
14

Description

I have the following definition in my schema:

"ID": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://raw.githubusercontent.com/flexiblepower/s2-ws-json/main/s2-json-schema/schemas/ID",
    "title": "ID",
    "type": "string",
    "pattern": "[a-zA-Z0-9\\-_:]{2,64}",
    "description": "An identifier expressed as a UUID"
}

Using import_types! to generate structs for this results in the following type:

pub struct Id(String);

This tuple struct has a private field, which means that it can't easily be constructed outside of the module it's defined in, i.e. trying to create an Id("abcd-1234".to_string()) gives the error tuple struct constructor Id is private.

I would expect the fields of generated tuple structs to be public, just like the fields of regular generated structs. I can work around this by defining a new function for types where this happens, but would prefer to use the types as-is.

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Trace the import_types! path that generates the Id tuple struct, then compare its field visibility with regular generated structs. Done means a generated constrained type can be constructed outside its defining module, while preserving the documented constrained-type behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.