Skip to content

Implement default values for references#194

Merged
simu merged 11 commits intomainfrom
feat/reference-default-values
Dec 16, 2025
Merged

Implement default values for references#194
simu merged 11 commits intomainfrom
feat/reference-default-values

Conversation

@simu
Copy link
Copy Markdown
Member

@simu simu commented Nov 25, 2025

We treat :: as the delimiter between reference path and default value. Note that this is technically a breaking change for existing reclass-rs inventories.

The implementation currently first resolves all nested references in both the reference and the default value parts before even looking for : and ::.

We always parse the default value as YAML to support complex default values (directly or via reference) and to provide the most intuitive default value behavior (any valid YAML snippets are used as typed values, and malformed snippets raise errors).

To make usage of simple default values more intuitive, we convert parsed string default value into Value::Literal to avoid incorrect additional reference resolution. We know that we've already resolved the top-level nested references at the time we parse a default value.

Note that we don't want to recursively replace Value::String with Value::Literal so that default values which are references that expand to complex values still get resolved correctly.

Generally, we recommend that users use references when they want to provide complex default values, since complex default values which are provided inline require special care to not confuse the reference and default parsers.

Checklist

  • The PR has a meaningful title. The title will be used to auto generate the changelog
  • PR contains a single logical change (to build a better changelog).
  • Update the documentation.
  • Update tests.
  • Categorize the PR by setting a good title and adding one of the labels:
    bug, enhancement, documentation, change, breaking, dependency, internal
    as they show up in the changelog

@github-actions

This comment was marked as outdated.

@simu simu force-pushed the feat/reference-default-values branch from 6f75bd1 to 4b99f91 Compare November 26, 2025 12:16
@github-actions

This comment was marked as outdated.

Base automatically changed from feat/rust-2024 to main November 27, 2025 12:40
@simu simu force-pushed the feat/reference-default-values branch from 4b99f91 to fd14f61 Compare November 27, 2025 15:12
@github-actions

This comment was marked as outdated.

@simu simu force-pushed the feat/reference-default-values branch from fd14f61 to b1f37e7 Compare November 27, 2025 15:22
@github-actions

This comment was marked as outdated.

@simu simu force-pushed the feat/reference-default-values branch from b1f37e7 to e0cd521 Compare November 27, 2025 15:29
@github-actions

This comment was marked as outdated.

@simu simu force-pushed the feat/reference-default-values branch from e0cd521 to 4baf48d Compare November 28, 2025 09:50
@github-actions

This comment was marked as outdated.

@simu simu force-pushed the feat/reference-default-values branch from 4baf48d to 06d1f53 Compare November 28, 2025 10:25
@github-actions

This comment was marked as outdated.

@simu simu force-pushed the feat/reference-default-values branch from 06d1f53 to 23d73d8 Compare November 28, 2025 10:51
@github-actions

This comment was marked as outdated.

@simu simu force-pushed the feat/reference-default-values branch from 23d73d8 to fdc75d8 Compare November 28, 2025 11:03
@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@simu simu force-pushed the feat/reference-default-values branch from cec208b to 0e1a8f9 Compare November 28, 2025 13:58
@github-actions

This comment was marked as outdated.

@simu simu force-pushed the feat/reference-default-values branch from 0e1a8f9 to 1bf077e Compare November 28, 2025 14:40
@github-actions

This comment was marked as outdated.

simu added 4 commits November 28, 2025 15:43
We treat `::` as the delimiter between reference path and default value.

The implementation currently first resolves all nested references in
both the reference and the default value parts before even looking for
`:` and `::`.

We always parse the default value as YAML to support complex default
values (directly or via reference) and to provide the most intuitive
default value behavior (any valid YAML snippets are used as typed
values, and malformed snippets raise errors).

more default value
We didn't have an `IntoIterator for Mapping` implementation for our
Mapping type yet. This can be useful to minimize allocations if we're
replacing a Mapping with another mapping while modifying only a fraction
the contents.
… to `Value::Literal`

Convert parsed string default value into Value::Literal to avoid
incorrect additional reference resolution. We know that we've already
resolved the top-level nested references at the time we call
`extract_path_and_default`.

Note that we don't want to recursively replace `Value::String` with
`Value::Literal` so that default values which are references that expand
to complex values still get resolved correctly.
simu added 5 commits November 28, 2025 15:43
…t value

The debug messages are only printed out if `verbose_warnings` is set to
`true` when rendering the inventory.
Add `README-extensions.md` to document reclass-rs specific extensions
and update `README.md` to link to the new file.
@simu simu force-pushed the feat/reference-default-values branch from 1bf077e to 73ef9e7 Compare November 28, 2025 15:05
@github-actions
Copy link
Copy Markdown

Benchmark for 7a2368a

Click to view benchmark
Test Base PR %
Reclass::inventory() multi-threaded 2.3±0.12ms 2.3±0.14ms 0.00%
Reclass::inventory() single-threaded 4.6±0.09ms 4.6±0.06ms 0.00%

@simu simu marked this pull request as ready for review November 28, 2025 15:30
@simu simu requested a review from a team November 28, 2025 15:30
@simu
Copy link
Copy Markdown
Member Author

simu commented Nov 28, 2025

If you have a bit of time when reviewing please think about potentially missing test cases.

@simu simu changed the title Draft: Add support for default values for missing references Implement default values for references Nov 28, 2025
Copy link
Copy Markdown
Member

@bastjan bastjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

Did not find any additionally required test cases from the top of my head.

Comment thread src/refs/token_resolve_parse_tests.rs
@simu simu merged commit a1828fb into main Dec 16, 2025
22 checks passed
@simu simu deleted the feat/reference-default-values branch December 16, 2025 13:47
@simu simu added enhancement New feature or request breaking labels Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants