Implemented the NotEmptyValidationRule type in the library target.

This commit is contained in:
2025-10-12 13:57:54 +02:00
parent 8c68ae9417
commit 630f8a03f7
@@ -0,0 +1,38 @@
// ===----------------------------------------------------------------------===
//
// This source file is part of the DiscogsService open source project
//
// Copyright (c) 2025 Röck+Cöde VoF. and the DiscogsService project authors
// Licensed under Apache license v2.0
//
// See LICENSE for license information
// See CONTRIBUTORS for the list of DiscogsService project authors
//
// SPDX-License-Identifier: Apache-2.0
//
// ===----------------------------------------------------------------------===
/// A validation rule type that checks whether an input is empty or not.
struct NotEmptyValidationRule: InputValidationRule {
// MARK: Functions
func validate(_ input: String?) throws -> Bool {
guard let input else {
return false
}
guard !input.isEmpty else {
throw InputValidationError.inputIsEmpty
}
return true
}
}
// MARK: - Constants
extension InputValidationRule where Self == NotEmptyValidationRule {
/// A validation rule that checks whether an input is empty or not.
static var notEmpty: Self { .init() }
}