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 encodable provides 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. Passing nil uses the existing monotonic numeric counter and skips all active reservations.

    The returned Anchor instance is authoritative. Custom aliasing strategies must retain and use that exact instance in their aliasing outcomes.

    Declaration

    Swift

    public func uniqueAlias(preferredAnchor: Anchor?) -> Anchor
  • Releases all active anchor reservations and retained anchor identities.

    The numeric counter remains monotonic and is not reset.

    Declaration

    Swift

    public func releaseAnchorReferences()
  • Releases the reservation for an issued anchor only when anchor is the exact issued instance.

    A different Anchor instance with the same raw value is ignored.

    Declaration

    Swift

    public func remit(anchor: Anchor)