Skip to content

Plans to stabilize unstable.Unmarshaler? #1122

Description

@tisonkun

Hi, and thank you for maintaining go-toml.

I am evaluating how to decode a TOML discriminated union. A simplified shape is:

[[downloads]]
type = "github_release"
repository = "owner/repo"
tag = "v1.0.0"
asset = "bundle.yaml"

[[downloads]]
type = "github_raw_user_content"
repository = "owner/repo"
revision = "0123456789abcdef"
source = "path/to/file.yaml"

In Rust this can be represented with serde tagged enums, such as #[serde(tag = "type")]. As far as I can tell, go-toml/v2 does not currently provide an equivalent first-class mapping. The available approach is to implement unstable.Unmarshaler and opt in with Decoder.EnableUnmarshalerInterface().

The documentation says that this API does not follow the library semver compatibility guarantees and may change or be removed without a major release. I saw that #873 was completed by #1027, including support for tables and arrays of tables.

Is there a plan to stabilize this interface, possibly by moving Unmarshaler and RawMessage out of unstable? If so, are there known blockers or stability criteria?

If stabilization is not planned, what stable approach would you recommend for discriminated unions: decoding into an intermediate struct or map and dispatching manually, or something else?

Thank you.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions