public extension PureYAML.Validation { /// A type-erased `Validation`, so checks specialised on different subject types live in one list, all /// sharing one `Document` (the validated tree's root type). It filters by runtime type: a /// `Validation` fires only on a `Subject` value, never on an optional of it (the /// `type(of:)` guard) or a value of any other type. struct AnyValidation: Sendable { public let description: String private let applyErased: @Sendable (any Validatable, Path, Document) -> [ValidationError] public init(_ validation: Validation) { description = validation.description applyErased = { subject, path, document in guard let typed = subject as? Subject, type(of: subject) == Subject.self else { return [] } return validation.apply(ValidationContext(document: document, subject: typed, path: path)) } } public func apply( to subject: any Validatable, at path: Path, in document: Document, ) -> [ValidationError] { applyErased(subject, path, document) } } }