Skip to content

Support variants #8

@andry-dev

Description

@andry-dev

The parser does not support sum-types (C++'s std::variants, Rust enums, ...), but it may be helpful to support them. How would a definition look like?

json Foo {
    // ...

    sum name {
        variant type="Bar" {
            key "a"
        }

        variant type="Baz" {
            key "b"
        }
    }
}

Ideas

  • Calling it enum overloads the terms used for int-enum and str-enum, I would make it completely different (like the sum, which is closer to algebraic/type-theory).
  • A sum-type variant must not contain optional #true. All elements must be equally possible.
  • Nesting sum inside sum should not be possible (just make a new type).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions