Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find Some Way to Create Schemas for Recursive Types #493

Open
zicklag opened this issue Dec 11, 2024 · 0 comments
Open

Find Some Way to Create Schemas for Recursive Types #493

zicklag opened this issue Dec 11, 2024 · 0 comments

Comments

@zicklag
Copy link
Member

zicklag commented Dec 11, 2024

It's not something that we have found a hard requirement for yet, but it is something that has come up once or twice for a friend that it's not possible to derive HasSchema for a recursive type. I.e.

struct Expr {
  Vec(Vec<Expr>),
  String(String),
  None,
}

The issue is with the first variant in which Expr references Expr. In the schema derive, we want to then find out the schema of Expr and stick it in the Vec<Expr>, but the problem is that we're in the middle of actively building the Expr schema. This causes an infinite loop of trying to build the schema of Expr so we can build the schema Expr and so on.

One possible solution would be to have something like a self or parent placeholder so that the schema could refer to it's own schema, but I'm not actually sure if that works or not.

Another interesting idea in a related dilemma for content-addressed self-referentiality is this one here:

https://whtwnd.com/makoconstruct.bsky.social/3lcdzw5oqh62t

It could work, but I haven't thought all the way through it. I just wanted to drop it here so it isn't forgotten.

Summary of the idea from that post:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant