dtolnay / serde-yaml

Strongly typed YAML library for Rust
Apache License 2.0
965 stars 164 forks source link

Supporting YAML references (anchors and aliases) #245

Closed milesj closed 2 years ago

milesj commented 2 years ago

I can't seem to get these to work, although yaml-rust looks to support them upstream. Given the following code:

tasks:
    build: &webpack_shared
        command: webpack
        args: build
        inputs:
            - 'src/**/*'
    start:
        <<: *webpack_shared
        args: start

I'd expect tasks.start to inherit command and inputs, with args being overridden. However, both command and inputs are None once deserialized.

It also seems like anchors assigned at the top-level to fake fields are also not supported.

_webpack_shared: &webpack_shared
    command: webpack
    inputs:
        - 'src/**/*'

tasks:
    build:
        <<: *webpack_shared
        args: build
    start:
        <<: *webpack_shared
        args: start

Has anyone actually gotten these to work?

dtolnay commented 2 years ago

This is implemented in 0.9. https://docs.rs/serde_yaml/0.9/serde_yaml/enum.Value.html#method.apply_merge