Skip to content

Find Some Way to Create Schemas for Recursive Types #493

@zicklag

Description

@zicklag

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions