From ccbdbc8392988c534c636c2fe675ae07c386e98a Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Thu, 11 Apr 2024 09:22:50 +0100 Subject: [PATCH] Update swift format to 5.8 --- .swiftformat | 4 +-- .../soto-benchmark/EncoderSuites.swift | 6 ++-- Sources/SotoCore/AWSClient+Paginate.swift | 2 +- Sources/SotoCore/AWSClient.swift | 12 +++---- Sources/SotoCore/AWSServiceConfig.swift | 4 +-- Sources/SotoCore/AWSShapes/Base64Data.swift | 2 +- .../SotoCore/Credential/STSAssumeRole.swift | 2 +- Sources/SotoCore/Doc/AWSShape.swift | 30 ++++++++-------- .../CodableProperties/CodableProperties.swift | 2 +- Sources/SotoCore/Encoder/QueryEncoder.swift | 10 +++--- .../SotoCore/Encoder/RequestContainer.swift | 34 +++++++++---------- Sources/SotoCore/HTTP/AWSHTTPBody.swift | 2 +- Sources/SotoCore/HTTP/AWSHTTPRequest.swift | 6 ++-- Sources/SotoCore/HTTP/AWSHTTPResponse.swift | 2 +- .../SotoCore/Middleware/MiddlewareStack.swift | 6 ++-- Sources/SotoCore/Utils/base64.swift | 18 +++++----- Sources/SotoCore/Utils/crc32.swift | 4 +-- Sources/SotoSignerV4/signer.swift | 6 ++-- Sources/SotoTestUtils/TestServer.swift | 4 +-- Sources/SotoXML/Expat.swift | 4 +-- Sources/SotoXML/XML.swift | 10 +++--- Sources/SotoXML/XMLDecoder.swift | 4 +-- Sources/SotoXML/XMLEncoder.swift | 10 +++--- .../Concurrency/AsyncSequenceTests.swift | 2 +- Tests/SotoCoreTests/MiddlewareTests.swift | 4 +-- Tests/SotoCoreTests/QueryEncoderTests.swift | 2 +- Tests/SotoCoreTests/TestTracer.swift | 12 +++---- 27 files changed, 101 insertions(+), 103 deletions(-) diff --git a/.swiftformat b/.swiftformat index 12243eed5..29880d765 100644 --- a/.swiftformat +++ b/.swiftformat @@ -2,13 +2,13 @@ --minversion 0.51.0 # Swift version ---swiftversion 5.5 +--swiftversion 5.8 # file options --exclude .build # rules ---disable redundantReturn, extensionAccessControl +--disable redundantReturn, extensionAccessControl, typeSugar # format options --ifdef no-indent diff --git a/Benchmark/Sources/soto-benchmark/EncoderSuites.swift b/Benchmark/Sources/soto-benchmark/EncoderSuites.swift index 3ad167338..238f303d7 100644 --- a/Benchmark/Sources/soto-benchmark/EncoderSuites.swift +++ b/Benchmark/Sources/soto-benchmark/EncoderSuites.swift @@ -28,14 +28,14 @@ protocol EncoderProtocol { extension XMLEncoder: EncoderProtocol { typealias Output = XML.Element - func encode(_ value: Input) throws -> Output { + func encode(_ value: some Encodable) throws -> Output { try self.encode(value, name: "BenchmarkTest") } } extension QueryEncoder: EncoderProtocol { typealias Output = String? - func encode(_ value: Input) throws -> Output { + func encode(_ value: some Encodable) throws -> Output { try self.encode(value, name: "BenchmarkTest") } } @@ -62,7 +62,7 @@ struct Dictionaries: Codable { } /// Generic suite of benchmark tests for an Encoder. -func encoderSuite(for encoder: E, suite: BenchmarkSuite) { +func encoderSuite(for encoder: some EncoderProtocol, suite: BenchmarkSuite) { let numbers = Numbers(b: true, i: 3478, f: 34.4633, d: 9585) suite.benchmark("numbers") { _ = try encoder.encode(numbers) diff --git a/Sources/SotoCore/AWSClient+Paginate.swift b/Sources/SotoCore/AWSClient+Paginate.swift index f49b60901..4b6860599 100644 --- a/Sources/SotoCore/AWSClient+Paginate.swift +++ b/Sources/SotoCore/AWSClient+Paginate.swift @@ -68,7 +68,7 @@ extension AWSClient { } public mutating func next() async throws -> Output? { - if let input = input { + if let input { let output = try await self.sequence.command(input, self.sequence.logger) if let token = output[keyPath: sequence.outputKey], sequence.inputKey == nil || token != input[keyPath: sequence.inputKey!], diff --git a/Sources/SotoCore/AWSClient.swift b/Sources/SotoCore/AWSClient.swift index a93008466..258adf2ad 100644 --- a/Sources/SotoCore/AWSClient.swift +++ b/Sources/SotoCore/AWSClient.swift @@ -64,10 +64,10 @@ public final class AWSClient: Sendable { /// - options: Configuration flags /// - httpClient: HTTPClient to use. /// - logger: Logger used to log background AWSClient events - public init( + public init( credentialProvider credentialProviderFactory: CredentialProviderFactory = .default, retryPolicy retryPolicyFactory: RetryPolicyFactory = .default, - middleware: Middleware, + middleware: some AWSMiddlewareProtocol, options: Options = Options(), httpClient: AWSHTTPClient = HTTPClient.shared, logger clientLogger: Logger = AWSClient.loggingDisabled @@ -227,12 +227,12 @@ extension AWSClient { /// - input: Input object /// - hostPrefix: String to prefix host name with /// - logger: Logger to log request details to - public func execute( + public func execute( operation operationName: String, path: String, httpMethod: HTTPMethod, serviceConfig: AWSServiceConfig, - input: Input, + input: some AWSEncodableShape, hostPrefix: String? = nil, logger: Logger = AWSClient.loggingDisabled ) async throws { @@ -337,12 +337,12 @@ extension AWSClient { /// - logger: Logger to log request details to /// - returns: /// Output object that completes when response is received - public func execute( + public func execute( operation operationName: String, path: String, httpMethod: HTTPMethod, serviceConfig: AWSServiceConfig, - input: Input, + input: some AWSEncodableShape, hostPrefix: String? = nil, logger: Logger = AWSClient.loggingDisabled ) async throws -> Output { diff --git a/Sources/SotoCore/AWSServiceConfig.swift b/Sources/SotoCore/AWSServiceConfig.swift index fd449636f..5197eac04 100644 --- a/Sources/SotoCore/AWSServiceConfig.swift +++ b/Sources/SotoCore/AWSServiceConfig.swift @@ -91,7 +91,7 @@ public final class AWSServiceConfig { options: Options = [] ) { var partition = partition - if let region = region { + if let region { self.region = region partition = region.partition } else if let partitionEndpoint = partitionEndpoints[partition] { @@ -142,7 +142,7 @@ public final class AWSServiceConfig { variantEndpoints: [EndpointVariantType: EndpointVariant] ) -> String { // work out endpoint, if provided use that otherwise - if let endpoint = endpoint { + if let endpoint { return endpoint } else { let serviceHost: String diff --git a/Sources/SotoCore/AWSShapes/Base64Data.swift b/Sources/SotoCore/AWSShapes/Base64Data.swift index 5e859f7c5..8b4a08a45 100644 --- a/Sources/SotoCore/AWSShapes/Base64Data.swift +++ b/Sources/SotoCore/AWSShapes/Base64Data.swift @@ -23,7 +23,7 @@ public struct AWSBase64Data: Sendable, Codable, Equatable { } /// construct `AWSBase64Data` from raw data - public static func data(_ data: C) -> Self where C.Element == UInt8 { + public static func data(_ data: some Collection) -> Self { return .init(base64String: String(base64Encoding: data)) } diff --git a/Sources/SotoCore/Credential/STSAssumeRole.swift b/Sources/SotoCore/Credential/STSAssumeRole.swift index 272112e60..dce1dfc9e 100644 --- a/Sources/SotoCore/Credential/STSAssumeRole.swift +++ b/Sources/SotoCore/Credential/STSAssumeRole.swift @@ -218,7 +218,7 @@ struct STSAssumeRoleCredentialProvider: CredentialProviderWithClient { let request = STSAssumeRoleWithWebIdentityRequest(roleArn: arn, roleSessionName: sessioName, webIdentityToken: token) credentials = try await self.assumeRoleWithWebIdentity(request, logger: logger).credentials } - guard let credentials = credentials else { + guard let credentials else { throw CredentialProviderError.noProvider } return credentials diff --git a/Sources/SotoCore/Doc/AWSShape.swift b/Sources/SotoCore/Doc/AWSShape.swift index f80d04df2..80e97ef13 100644 --- a/Sources/SotoCore/Doc/AWSShape.swift +++ b/Sources/SotoCore/Doc/AWSShape.swift @@ -84,11 +84,11 @@ public extension AWSEncodableShape { guard value <= max else { throw Self.validationError("\(parent).\(name) (\(value)) is greater than the maximum allowed value \(max).") } } - func validate(_ value: T, name: String, parent: String, min: Int) throws { + func validate(_ value: some Collection, name: String, parent: String, min: Int) throws { guard value.count >= min else { throw Self.validationError("Length of \(parent).\(name) (\(value.count)) is less than minimum allowed value \(min).") } } - func validate(_ value: T, name: String, parent: String, max: Int) throws { + func validate(_ value: some Collection, name: String, parent: String, max: Int) throws { guard value.count <= max else { throw Self.validationError("Length of \(parent).\(name) (\(value.count)) is greater than the maximum allowed value \(max).") } } @@ -125,57 +125,57 @@ public extension AWSEncodableShape { // validate optional values func validate(_ value: T?, name: String, parent: String, min: T) throws { - guard let value = value else { return } + guard let value else { return } try self.validate(value, name: name, parent: parent, min: min) } func validate(_ value: T?, name: String, parent: String, max: T) throws { - guard let value = value else { return } + guard let value else { return } try self.validate(value, name: name, parent: parent, max: max) } func validate(_ value: T?, name: String, parent: String, min: T) throws { - guard let value = value else { return } + guard let value else { return } try self.validate(value, name: name, parent: parent, min: min) } func validate(_ value: T?, name: String, parent: String, max: T) throws { - guard let value = value else { return } + guard let value else { return } try self.validate(value, name: name, parent: parent, max: max) } - func validate(_ value: T?, name: String, parent: String, min: Int) throws { - guard let value = value else { return } + func validate(_ value: (some Collection)?, name: String, parent: String, min: Int) throws { + guard let value else { return } try self.validate(value, name: name, parent: parent, min: min) } - func validate(_ value: T?, name: String, parent: String, max: Int) throws { - guard let value = value else { return } + func validate(_ value: (some Collection)?, name: String, parent: String, max: Int) throws { + guard let value else { return } try self.validate(value, name: name, parent: parent, max: max) } func validate(_ value: AWSBase64Data?, name: String, parent: String, min: Int) throws { - guard let value = value else { return } + guard let value else { return } try self.validate(value, name: name, parent: parent, min: min) } func validate(_ value: AWSBase64Data?, name: String, parent: String, max: Int) throws { - guard let value = value else { return } + guard let value else { return } try self.validate(value, name: name, parent: parent, max: max) } func validate(_ value: AWSHTTPBody?, name: String, parent: String, min: Int) throws { - guard let value = value else { return } + guard let value else { return } try self.validate(value, name: name, parent: parent, min: min) } func validate(_ value: AWSHTTPBody?, name: String, parent: String, max: Int) throws { - guard let value = value else { return } + guard let value else { return } try self.validate(value, name: name, parent: parent, max: max) } func validate(_ value: String?, name: String, parent: String, pattern: String) throws { - guard let value = value else { return } + guard let value else { return } try self.validate(value, name: name, parent: parent, pattern: pattern) } } diff --git a/Sources/SotoCore/Encoder/CodableProperties/CodableProperties.swift b/Sources/SotoCore/Encoder/CodableProperties/CodableProperties.swift index c0cfc4b2f..cae8d30de 100644 --- a/Sources/SotoCore/Encoder/CodableProperties/CodableProperties.swift +++ b/Sources/SotoCore/Encoder/CodableProperties/CodableProperties.swift @@ -126,7 +126,7 @@ extension KeyedDecodingContainer { /// extending `KeyedEncodingContainer` so it will only encode a wrapped value it is non nil extension KeyedEncodingContainer { // Used to make make sure OptionalCodingWrappers encode no value when it's wrappedValue is nil. - public mutating func encode(_ value: T, forKey key: KeyedEncodingContainer.Key) throws where T: Encodable, T: OptionalCustomCodingWrapper { + public mutating func encode(_ value: some Encodable & OptionalCustomCodingWrapper, forKey key: KeyedEncodingContainer.Key) throws { guard value.wrappedValue != nil else { return } try encodeIfPresent(value, forKey: key) } diff --git a/Sources/SotoCore/Encoder/QueryEncoder.swift b/Sources/SotoCore/Encoder/QueryEncoder.swift index 2f5f388be..e1069a510 100644 --- a/Sources/SotoCore/Encoder/QueryEncoder.swift +++ b/Sources/SotoCore/Encoder/QueryEncoder.swift @@ -40,7 +40,7 @@ public struct QueryEncoder { public init() {} - public func encode(_ value: T) throws -> String? { + public func encode(_ value: some Encodable) throws -> String? { let encoder = _QueryEncoder(options: options) try value.encode(to: encoder) @@ -94,7 +94,7 @@ public struct QueryEncoder { } } } - if let container = container { + if let container { flatten(dictionary: container.values, path: "") } return result @@ -222,7 +222,7 @@ private class _QueryEncoder: Encoder { mutating func encode(_ value: UInt32, forKey key: Key) throws { self.encode(value, key: key.stringValue) } mutating func encode(_ value: UInt64, forKey key: Key) throws { self.encode(value, key: key.stringValue) } - mutating func encode(_ value: T, forKey key: Key) throws { + mutating func encode(_ value: some Encodable, forKey key: Key) throws { self.encoder.codingPath.append(key) defer { self.encoder.codingPath.removeLast() } @@ -305,7 +305,7 @@ private class _QueryEncoder: Encoder { mutating func encode(_ value: UInt32) throws { self.encodeResult(value) } mutating func encode(_ value: UInt64) throws { self.encodeResult(value) } - mutating func encode(_ value: T) throws { + mutating func encode(_ value: some Encodable) throws { self.count += 1 self.encoder.codingPath.append(_QueryKey(index: self.count)) @@ -367,7 +367,7 @@ extension _QueryEncoder: SingleValueEncodingContainer { func encode(_ value: UInt32) throws { self.encodeResult(value) } func encode(_ value: UInt64) throws { self.encodeResult(value) } - func encode(_ value: T) throws { + func encode(_ value: some Encodable) throws { try value.encode(to: self) } diff --git a/Sources/SotoCore/Encoder/RequestContainer.swift b/Sources/SotoCore/Encoder/RequestContainer.swift index b227a3529..3826c1cd6 100644 --- a/Sources/SotoCore/Encoder/RequestContainer.swift +++ b/Sources/SotoCore/Encoder/RequestContainer.swift @@ -84,14 +84,14 @@ public class RequestEncodingContainer { /// Write value to header @inlinable - public func encodeHeader(_ value: Value, key: String) { + public func encodeHeader(_ value: some Any, key: String) { self.headers.replaceOrAdd(name: key, value: "\(value)") } /// Write optional value to header @inlinable - public func encodeHeader(_ value: Value?, key: String) { - if let value = value { + public func encodeHeader(_ value: (some Any)?, key: String) { + if let value { self.encodeHeader(value, key: key) } } @@ -120,7 +120,7 @@ public class RequestEncodingContainer { /// Write dictionary key value pairs to headers with prefix added to the keys @inlinable - public func encodeHeader(_ value: [String: Value], key prefix: String) { + public func encodeHeader(_ value: [String: some Any], key prefix: String) { for element in value { self.headers.replaceOrAdd(name: "\(prefix)\(element.key)", value: "\(element.value)") } @@ -128,8 +128,8 @@ public class RequestEncodingContainer { /// Write optional dictionary key value pairs to headers with prefix added to the keys @inlinable - public func encodeHeader(_ value: [String: Value]?, key prefix: String) { - if let value = value { + public func encodeHeader(_ value: [String: some Any]?, key prefix: String) { + if let value { self.encodeHeader(value, key: prefix) } } @@ -138,14 +138,14 @@ public class RequestEncodingContainer { /// Write value to query @inlinable - public func encodeQuery(_ value: Value, key: String) { + public func encodeQuery(_ value: some Any, key: String) { self.queryParams.append((key: key, value: "\(value)")) } /// Write optional value to query @inlinable - public func encodeQuery(_ value: Value?, key: String) { - if let value = value { + public func encodeQuery(_ value: (some Any)?, key: String) { + if let value { self.queryParams.append((key: key, value: "\(value)")) } } @@ -168,7 +168,7 @@ public class RequestEncodingContainer { /// Write array as a series of query values @inlinable - public func encodeQuery(_ value: [Value], key: String) { + public func encodeQuery(_ value: [some Any], key: String) { for element in value { self.queryParams.append((key: key, value: "\(element)")) } @@ -176,7 +176,7 @@ public class RequestEncodingContainer { /// Write dictionary key value pairs as query key value pairs @inlinable - public func encodeQuery(_ value: [String: Value]) { + public func encodeQuery(_ value: [String: some Any]) { for element in value { self.queryParams.append((key: element.key, value: "\(element.value)")) } @@ -184,23 +184,23 @@ public class RequestEncodingContainer { /// Write optional array as a series of query values @inlinable - public func encodeQuery(_ value: [Value]?, key: String) { - if let value = value { + public func encodeQuery(_ value: [some Any]?, key: String) { + if let value { self.encodeQuery(value, key: key) } } /// Write optional dictionary key value pairs as query key value pairs @inlinable - public func encodeQuery(_ value: [String: Value]?) { - if let value = value { + public func encodeQuery(_ value: [String: some Any]?) { + if let value { self.encodeQuery(value) } } /// Write value into URI path @inlinable - public func encodePath(_ value: Value, key: String) { + public func encodePath(_ value: some Any, key: String) { self.path = self.path .replacingOccurrences(of: "{\(key)}", with: Self.urlEncodePathComponent(String(describing: value))) .replacingOccurrences(of: "{\(key)+}", with: Self.urlEncodePath(String(describing: value))) @@ -208,7 +208,7 @@ public class RequestEncodingContainer { /// Write value into hostname @inlinable - public func encodeHostPrefix(_ value: Value, key: String) { + public func encodeHostPrefix(_ value: some Any, key: String) { self.hostPrefix = self.hostPrefix? .replacingOccurrences(of: "{\(key)}", with: Self.urlEncodePathComponent(String(describing: value))) } diff --git a/Sources/SotoCore/HTTP/AWSHTTPBody.swift b/Sources/SotoCore/HTTP/AWSHTTPBody.swift index 007945930..540fe4c2c 100644 --- a/Sources/SotoCore/HTTP/AWSHTTPBody.swift +++ b/Sources/SotoCore/HTTP/AWSHTTPBody.swift @@ -35,7 +35,7 @@ public struct AWSHTTPBody: Sendable { self.storage = .byteBuffer(buffer) } - public init(bytes: C, byteBufferAllocator: ByteBufferAllocator = .init()) where C.Element == UInt8 { + public init(bytes: some Collection, byteBufferAllocator: ByteBufferAllocator = .init()) { var byteBuffer = byteBufferAllocator.buffer(capacity: bytes.count) byteBuffer.writeBytes(bytes) self.storage = .byteBuffer(byteBuffer) diff --git a/Sources/SotoCore/HTTP/AWSHTTPRequest.swift b/Sources/SotoCore/HTTP/AWSHTTPRequest.swift index c86bcb985..7f1539551 100644 --- a/Sources/SotoCore/HTTP/AWSHTTPRequest.swift +++ b/Sources/SotoCore/HTTP/AWSHTTPRequest.swift @@ -141,7 +141,7 @@ extension AWSHTTPRequest { var encoder = XMLEncoder() encoder.userInfo[.awsRequest] = requestEncoderContainer let xml = try encoder.encode(input, name: Input._xmlRootNodeName) - if let xml = xml, xml.childCount > 0 { + if let xml, xml.childCount > 0 { if let xmlNamespace = Input._xmlNamespace ?? configuration.xmlNamespace { xml.addNamespace(XML.Node.namespace(stringValue: xmlNamespace)) } @@ -220,7 +220,7 @@ extension AWSHTTPRequest { } } - guard let checksumType = checksumType, + guard let checksumType, case .byteBuffer(let buffer) = body.storage, let checksumHeader = Self.checksumHeaders[checksumType], headers[checksumHeader].first == nil else { return headers } @@ -250,7 +250,7 @@ extension AWSHTTPRequest { case .md5: checksum = self.calculateChecksum(buffer, function: Insecure.MD5.self) } - if let checksum = checksum { + if let checksum { headers.add(name: checksumHeader, value: checksum) } return headers diff --git a/Sources/SotoCore/HTTP/AWSHTTPResponse.swift b/Sources/SotoCore/HTTP/AWSHTTPResponse.swift index 1a3d49fe9..b5ed6ad9a 100644 --- a/Sources/SotoCore/HTTP/AWSHTTPResponse.swift +++ b/Sources/SotoCore/HTTP/AWSHTTPResponse.swift @@ -62,7 +62,7 @@ public struct AWSHTTPResponse { let payloadData: Data if self.isHypertextApplicationLanguage { payloadData = try self.getHypertextApplicationLanguageDictionary() - } else if let payload = payload, payload.readableBytes > 0 { + } else if let payload, payload.readableBytes > 0 { payloadData = Data(buffer: payload, byteTransferStrategy: .noCopy) } else { payloadData = Data("{}".utf8) diff --git a/Sources/SotoCore/Middleware/MiddlewareStack.swift b/Sources/SotoCore/Middleware/MiddlewareStack.swift index 58f2a00c2..12f739dcc 100644 --- a/Sources/SotoCore/Middleware/MiddlewareStack.swift +++ b/Sources/SotoCore/Middleware/MiddlewareStack.swift @@ -22,9 +22,9 @@ public enum AWSMiddlewareBuilder { first } - public static func buildPartialBlock( - accumulated m0: M0, - next m1: M1 + public static func buildPartialBlock( + accumulated m0: some AWSMiddlewareProtocol, + next m1: some AWSMiddlewareProtocol ) -> some AWSMiddlewareProtocol { AWSMiddleware2(m0, m1) } diff --git a/Sources/SotoCore/Utils/base64.swift b/Sources/SotoCore/Utils/base64.swift index 169599679..d56d0d66b 100644 --- a/Sources/SotoCore/Utils/base64.swift +++ b/Sources/SotoCore/Utils/base64.swift @@ -71,9 +71,7 @@ // MARK: - Extensions - extension String { - init(base64Encoding bytes: Buffer, options: Base64.EncodingOptions = []) - where Buffer.Element == UInt8 - { + init(base64Encoding bytes: some Collection, options: Base64.EncodingOptions = []) { self = Base64.encodeString(bytes: bytes, options: options) } @@ -219,8 +217,8 @@ extension Base64 { ] @inlinable - static func encodeBytes(bytes: Buffer, options: EncodingOptions = []) - -> [UInt8] where Buffer.Element == UInt8 + static func encodeBytes(bytes: some Collection, options: EncodingOptions = []) + -> [UInt8] { let newCapacity = ((bytes.count + 2) / 3) * 4 @@ -236,8 +234,8 @@ extension Base64 { } @inlinable - static func encodeString(bytes: Buffer, options: EncodingOptions = []) - -> String where Buffer.Element == UInt8 + static func encodeString(bytes: some Collection, options: EncodingOptions = []) + -> String { let newCapacity = ((bytes.count + 2) / 3) * 4 @@ -286,12 +284,12 @@ extension Base64 { buffer[outIndex] = e0[Int(i1)] - if let i2 = i2, let i3 = i3 { + if let i2, let i3 { buffer[outIndex + 1] = e1[Int(((i1 & 0x03) << 4) | ((i2 >> 4) & 0x0F))] buffer[outIndex + 2] = e1[Int(((i2 & 0x0F) << 2) | ((i3 >> 6) & 0x03))] buffer[outIndex + 3] = e1[Int(i3)] outIndex += 4 - } else if let i2 = i2 { + } else if let i2 { buffer[outIndex + 1] = e1[Int(((i1 & 0x03) << 4) | ((i2 >> 4) & 0x0F))] buffer[outIndex + 2] = e1[Int((i2 & 0x0F) << 2)] outIndex += 3 @@ -374,7 +372,7 @@ extension Base64 { } @inlinable - static func decode(bytes: Buffer, options: DecodingOptions = []) throws -> [UInt8] where Buffer.Element == UInt8 { + static func decode(bytes: some Collection, options: DecodingOptions = []) throws -> [UInt8] { guard bytes.count > 0 else { return [] } diff --git a/Sources/SotoCore/Utils/crc32.swift b/Sources/SotoCore/Utils/crc32.swift index 7fe8ea09c..1813ced08 100644 --- a/Sources/SotoCore/Utils/crc32.swift +++ b/Sources/SotoCore/Utils/crc32.swift @@ -167,7 +167,7 @@ private func crc32_with_table(crc: CRC32, buffer: UnsafeBufferPointer, ta /// - crc: base crc /// - bytes: buffer to calculate CRC32 for /// - Returns: crc32 checksum -public func soto_crc32(_ crc: CRC32, bytes: Buffer) -> CRC32 where Buffer.Element == UInt8 { +public func soto_crc32(_ crc: CRC32, bytes: some Collection) -> CRC32 { if let rest = bytes.withContiguousStorageIfAvailable({ buffer -> CRC32 in crc32_with_table(crc: crc, buffer: buffer, table: crc32Table) }) { @@ -184,7 +184,7 @@ public func soto_crc32(_ crc: CRC32, bytes: Buffer) -> CRC32 /// - crc: base crc /// - bytes: buffer to calculate CRC32 for /// - Returns: crc32c checksum -public func soto_crc32c(_ crc: CRC32, bytes: Buffer) -> CRC32 where Buffer.Element == UInt8 { +public func soto_crc32c(_ crc: CRC32, bytes: some Collection) -> CRC32 { if let rest = bytes.withContiguousStorageIfAvailable({ buffer -> CRC32 in crc32_with_table(crc: crc, buffer: buffer, table: crc32cTable) }) { diff --git a/Sources/SotoSignerV4/signer.swift b/Sources/SotoSignerV4/signer.swift index c8a4d3774..dda26ad95 100644 --- a/Sources/SotoSignerV4/signer.swift +++ b/Sources/SotoSignerV4/signer.swift @@ -359,7 +359,7 @@ public struct AWSSigner: Sendable { /// Create a SHA256 hash of the Requests body static func hashedPayload(_ payload: BodyData?) -> String { - guard let payload = payload else { return self.hashedEmptyBody } + guard let payload else { return self.hashedEmptyBody } let hash: String? switch payload { case .string(let string): @@ -376,7 +376,7 @@ public struct AWSSigner: Sendable { case .s3chunked: return "STREAMING-AWS4-HMAC-SHA256-PAYLOAD" } - if let hash = hash { + if let hash { return hash } else { return self.hashedEmptyBody @@ -434,7 +434,7 @@ extension String { } @_spi(SotoInternal) -public extension Sequence where Element == UInt8 { +public extension Sequence { /// return a hexEncoded string buffer from an array of bytes func hexDigest() -> String { return self.map { String(format: "%02x", $0) }.joined(separator: "") diff --git a/Sources/SotoTestUtils/TestServer.swift b/Sources/SotoTestUtils/TestServer.swift index c5a2f25de..45a794e3d 100644 --- a/Sources/SotoTestUtils/TestServer.swift +++ b/Sources/SotoTestUtils/TestServer.swift @@ -113,7 +113,7 @@ public class AWSTestServer { } /// run server reading request, convert from to an input shape processing them and converting the result back to a response. - public func process(_ process: (Input) throws -> Result) throws { + public func process(_ process: (Input) throws -> Result) throws { while try processSingleRequest(process) {} } @@ -312,7 +312,7 @@ extension AWSTestServer { } /// read one request, convert it from to an input shape, processing it and convert the result back to a response. - func processSingleRequest(_ process: (Input) throws -> Result) throws -> Bool { + func processSingleRequest(_ process: (Input) throws -> Result) throws -> Bool { let request = try readRequest() // Convert to Input AWSShape diff --git a/Sources/SotoXML/Expat.swift b/Sources/SotoXML/Expat.swift index d4cbf47c6..390f452dd 100644 --- a/Sources/SotoXML/Expat.swift +++ b/Sources/SotoXML/Expat.swift @@ -130,7 +130,7 @@ class Expat { Soto_XML_SetCommentHandler(self.parser) { ud, comment in let me = unsafeBitCast(ud, to: Expat.self) guard let callback = me.cbComment else { return } - guard let comment = comment else { return } + guard let comment else { return } callback(String(cString: comment)) } } @@ -181,7 +181,7 @@ class Expat { /// - Returns: attributes in dictionary form static func makeAttributesDictionary(_ attrs: UnsafeMutablePointer?>?) -> [String: String] { var sAttrs = [String: String]() - guard let attrs = attrs else { return sAttrs } + guard let attrs else { return sAttrs } var i = 0 while attrs[i] != nil { let name = String(cString: attrs[i]!) diff --git a/Sources/SotoXML/XML.swift b/Sources/SotoXML/XML.swift index f7d97af3e..e172c275d 100644 --- a/Sources/SotoXML/XML.swift +++ b/Sources/SotoXML/XML.swift @@ -121,25 +121,25 @@ public enum XML { public var xmlString: String { switch self.kind { case .text: - if let stringValue = stringValue { + if let stringValue { return XML.Node.xmlEncode(string: stringValue) } return "" case .attribute: - if let name = name { + if let name { return "\(name)=\"\(self.stringValue ?? "")\"" } else { return "" } case .comment: - if let stringValue = stringValue { + if let stringValue { return "" } else { return "" } case .namespace: var string = "xmlns" - if let name = name, name != "" { + if let name, name != "" { string += ":\(name)" } string += "=\"\(self.stringValue ?? "")\"" @@ -302,7 +302,7 @@ public enum XML { } set(value) { children?.removeAll { $0.kind == .text } - if let value = value { + if let value { self.addChild(XML.Node(.text, stringValue: value)) } } diff --git a/Sources/SotoXML/XMLDecoder.swift b/Sources/SotoXML/XMLDecoder.swift index a3fa3aaff..8ff765aac 100644 --- a/Sources/SotoXML/XMLDecoder.swift +++ b/Sources/SotoXML/XMLDecoder.swift @@ -605,7 +605,7 @@ private class _XMLDecoder: Decoder { } fileprivate func unbox(_ element: XML.Node?, as type: Date.Type) throws -> Date { - guard let element = element else { + guard let element else { throw DecodingError.keyNotFound(self.codingPath.last!, DecodingError.Context(codingPath: self.codingPath, debugDescription: "Key not found")) } @@ -620,7 +620,7 @@ private class _XMLDecoder: Decoder { /// get Data from XML.Node fileprivate func unbox(_ element: XML.Node?, as type: Data.Type) throws -> Data { - guard let element = element else { + guard let element else { throw DecodingError.keyNotFound(self.codingPath.last!, DecodingError.Context(codingPath: self.codingPath, debugDescription: "Key not found")) } switch self.options.dataDecodingStrategy { diff --git a/Sources/SotoXML/XMLEncoder.swift b/Sources/SotoXML/XMLEncoder.swift index 9b9804fe9..2ae32f02f 100644 --- a/Sources/SotoXML/XMLEncoder.swift +++ b/Sources/SotoXML/XMLEncoder.swift @@ -66,7 +66,7 @@ public struct XMLEncoder { public init() {} - public func encode(_ value: T, name: String? = nil) throws -> XML.Element? { + public func encode(_ value: some Encodable, name: String? = nil) throws -> XML.Element? { let rootName = name ?? "\(type(of: value))" let encoder = _XMLEncoder(options: options, codingPath: [_XMLKey(stringValue: rootName, intValue: nil)]) try value.encode(to: encoder) @@ -218,7 +218,7 @@ class _XMLEncoder: Encoder { self.element.addChild(childElement) } - func encode(_ value: T, forKey key: Key) throws where T: Encodable { + func encode(_ value: some Encodable, forKey key: Key) throws { // get element to attach child elements, also what to name those elements self.encoder.codingPath.append(key) defer { self.encoder.codingPath.removeLast() } @@ -365,7 +365,7 @@ class _XMLEncoder: Encoder { self.count += 1 } - mutating func encode(_ value: T) throws where T: Encodable { + mutating func encode(_ value: some Encodable) throws { self.encoder.codingPath.append(_XMLKey(stringValue: self.key, intValue: self.count)) defer { self.encoder.codingPath.removeLast() } @@ -467,7 +467,7 @@ extension _XMLEncoder: SingleValueEncodingContainer { try self.storage.push(container: XML.Element(name: self.currentKey, stringValue: box(value))) } - func encode(_ value: T) throws where T: Encodable { + func encode(_ value: some Encodable) throws { try self.storage.push(container: box(value)) } } @@ -597,7 +597,7 @@ private class _XMLReferencingEncoder: _XMLEncoder { // Finalizes `self` by writing the contents of our storage to the referenced encoder's storage. deinit { - if let element = element { + if let element { reference.addChild(element) } } diff --git a/Tests/SotoCoreTests/Concurrency/AsyncSequenceTests.swift b/Tests/SotoCoreTests/Concurrency/AsyncSequenceTests.swift index bd168802c..590ca02a7 100644 --- a/Tests/SotoCoreTests/Concurrency/AsyncSequenceTests.swift +++ b/Tests/SotoCoreTests/Concurrency/AsyncSequenceTests.swift @@ -31,7 +31,7 @@ final class AsyncSequenceTests: XCTestCase { var prevChunk: ByteBuffer? for try await chunk in chunkedSequence { // doing this so I don't check the length of the last chunk - if let prevChunk = prevChunk { + if let prevChunk { XCTAssertEqual(prevChunk.readableBytes, fixedChunkSize) } result.writeImmutableBuffer(chunk) diff --git a/Tests/SotoCoreTests/MiddlewareTests.swift b/Tests/SotoCoreTests/MiddlewareTests.swift index bafc58a75..8d2784124 100644 --- a/Tests/SotoCoreTests/MiddlewareTests.swift +++ b/Tests/SotoCoreTests/MiddlewareTests.swift @@ -27,8 +27,8 @@ class MiddlewareTests: XCTestCase { } } - func testMiddleware( - _ middleware: Middleware, + func testMiddleware( + _ middleware: some AWSMiddlewareProtocol, serviceName: String = "service", serviceOptions: AWSServiceConfig.Options = [], uri: String = "/", diff --git a/Tests/SotoCoreTests/QueryEncoderTests.swift b/Tests/SotoCoreTests/QueryEncoderTests.swift index 4199967d9..f013fac89 100644 --- a/Tests/SotoCoreTests/QueryEncoderTests.swift +++ b/Tests/SotoCoreTests/QueryEncoderTests.swift @@ -19,7 +19,7 @@ import XCTest class QueryEncoderTests: XCTestCase { @EnvironmentVariable("ENABLE_TIMING_TESTS", default: true) static var enableTimingTests: Bool - func testQuery(_ value: Input, query: String) { + func testQuery(_ value: some Encodable, query: String) { do { let query2 = try QueryEncoder().encode(value) XCTAssertEqual(query2, query) diff --git a/Tests/SotoCoreTests/TestTracer.swift b/Tests/SotoCoreTests/TestTracer.swift index 171dfd6c6..39d431af3 100644 --- a/Tests/SotoCoreTests/TestTracer.swift +++ b/Tests/SotoCoreTests/TestTracer.swift @@ -41,11 +41,11 @@ final class TestTracer: Tracer, Sendable { self.onEndSpan = onEndSpan } - func startSpan( + func startSpan( _ operationName: String, context: @autoclosure () -> ServiceContext, ofKind kind: SpanKind, - at instant: @autoclosure () -> Instant, + at instant: @autoclosure () -> some TracerInstant, function: String, file fileID: String, line: UInt @@ -165,9 +165,9 @@ final class TestSpan: Span, Sendable { let onEnd: @Sendable (TestSpan) -> Void - init( + init( operationName: String, - startTime: Instant, + startTime: some TracerInstant, context: ServiceContext, kind: SpanKind, onEnd: @escaping @Sendable (TestSpan) -> Void @@ -198,13 +198,13 @@ final class TestSpan: Span, Sendable { } } - func recordError(_ error: Error, attributes: SpanAttributes, at instant: @autoclosure () -> Instant) { + func recordError(_ error: Error, attributes: SpanAttributes, at instant: @autoclosure () -> some TracerInstant) { self._internal.withLockedValue { $0.recordedErrors.append((error, attributes)) } } - func end(at instant: @autoclosure () -> Instant) { + func end(at instant: @autoclosure () -> some TracerInstant) { self._internal.withLockedValue { $0.endTimestampNanosSinceEpoch = instant().nanosecondsSinceEpoch }