UniqueAliasProvider
public final class UniqueAliasProvider
A helper for assigning unique YAML anchor names to custom
RedundancyAliasingStrategy implementations.
Built-in strategies use uniqueAlias(for:), which preserves their existing behavior: a free
YamlAnchorProviding anchor is used as-is and a colliding preferred anchor follows the monotonic
numeric path. Custom strategies can opt in to preferred-name suffixing with
uniqueAlias(preferredAnchor:). The Anchor instances returned by this helper are authoritative;
custom strategies must retain and return those same instances in their
RedundancyAliasingOutcome values.
-
Creates a provider with an empty set of active anchor reservations.
Declaration
Swift
public init() -
Returns an anchor for an encodable value using the built-in strategy behavior.
If
encodableprovides a preferred anchor and that raw value is not currently reserved, the preferred anchor is returned unchanged. Otherwise, the next available monotonic numeric anchor is returned.Declaration
Swift
public func uniqueAlias(for encodable: any Encodable) -> Anchor -
Returns a unique anchor for an optional preferred anchor name.
Preferred-name matching is case-sensitive on
Anchor.rawValue. A free preferred anchor is returned unchanged and reserved. If its raw value is already reserved, new anchors are generated by appending_2,_3, and so on, skipping every currently reserved candidate, including names reserved independently with this method. Passingniluses the existing monotonic numeric counter and skips all active reservations.The returned
Anchorinstance is authoritative. Custom aliasing strategies must retain and use that exact instance in their aliasing outcomes. -
Releases all active anchor reservations and retained anchor identities.
The numeric counter remains monotonic and is not reset.
Declaration
Swift
public func releaseAnchorReferences()
View on GitHub
Install in Dash