Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Configuration #24] Support setting set #38

Open
loganmzz opened this issue Feb 9, 2025 · 0 comments
Open

[Configuration #24] Support setting set #38

loganmzz opened this issue Feb 9, 2025 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@loganmzz
Copy link
Owner

loganmzz commented Feb 9, 2025

General

Setting set is a way to change default setting values for some structs or fields without repeating same settings on every node.

Setting sets are defined as an ordered list in the Macon configuration file:

settingsets:
- id: "any"
  ...
- ...

Setting sets are applied in order. The latest overriding the previous ones. The id is optional is only used for debug purpose. It default to setting set order. Each setting set is compound of criteria and settings:

settingsets:
- id: ""       # Optional
  criteria: [] # Optional, default to match all
  settings: {} # Mandatory

Criteria

A setting set is applied (or retained) if current context (struct or field) matches the given criteria (TBD). Criteria are list of includes or excludes. In order to create exceptions.

# Include first to apply only on matching struct/field
- criteria:
  - includes: {} # Apply only if matches
  - excludes: {} # Ignore only in previous matches

# Exclude first to apply on all except matching struct/field
- criteria:
  - excludes: {} # Apply on if not matches
  - includes: {} # Retain only in previous matches

Each criterion is key which designate data to match. Then it contains a single key which is operator use for comparison. Supported criteria:
(Note: field criteria will never match for struct settings. However, field setting may applied to whole struct fields if criteria are only based on struct.)

  • keys: structs & fields can have key sets. It matches against the combine set of struct & field ones.
    • equals: set of keys that must be strictly specified on struct or field (combined).
    • contains: Sub-set of keys that must be specified on struct or field (combined).
  • struct_keys: it matches against keys defined at struct level.
    • equals: set of keys that must be strictly specified on struct.
    • contains: Sub-set of keys that must be specified on struct.
  • field_keys: it matches against keys defined at field level.
    • equals: set of keys that must be strictly specified on field.
    • contains: Sub-set of keys that must be specified on field.
  • struct_name: it matches against the struct name.
    • equals: string value that must equal the struct name.
    • matches: regular expression that must match the struct name.
  • field_name: it matches against the field name.
    • equals: string value that must equal the struct name.
    • matches: regular expression that must match the struct name.
  • field_type: canonical string representation of field type tokens. As Rust macros only operate on full text / token, it can't match on full/resolved type pathes; only as text as found in source code.
    • equals: string value that must equal field type representation.
    • matches: regular expression that must match field type representation.

Settings

There are divided in two categories: struct and field.

settingsets:
- criteria:
  settings:
    struct: {}
    field: {}

Supported struct settings:

  • Default: boolean indicating if struct derives Default. See Default struct.

Supported field settings:

  • Option:
  • Default: boolean indicating if field derives Default. See Default fields.
  • Into: Only false or "!" is supported. Disable Into for field setter. See Into argument.

When several setting sets matches, all their settings are applied in order of appearance (the lastest overriding previous ones).

For example:

# Configuration:
settingsets:
- settings:
    field:
      Default: false
      Option: "usize"
- settings:
    field:
      Option: false

# Result:
field:
  Default: false
  Option: false

Priority

Setting may come from several sources (the first find is used):

  • From a field attribute
  • From a struct attribute
  • From configuration setting sets
  • From configuration defaults
  • From defaults
@loganmzz loganmzz added the enhancement New feature or request label Feb 9, 2025
@loganmzz loganmzz self-assigned this Feb 9, 2025
loganmzz added a commit that referenced this issue Feb 16, 2025
loganmzz added a commit that referenced this issue Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant