Skip to content

Commit

Permalink
SwiftFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Feb 17, 2024
1 parent b20e403 commit 37a59af
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public struct URLEncodedFormEncoder: Sendable {
/// - Parameters:
/// - value: Value to encode
/// - Returns: URL encoded form data
public func encode<T: Encodable>(_ value: T) throws -> String {
public func encode(_ value: some Encodable) throws -> String {
let encoder = _URLEncodedFormEncoder(options: options)
try value.encode(to: encoder)
guard let result = encoder.result else {
Expand Down Expand Up @@ -158,7 +158,7 @@ private class _URLEncodedFormEncoder: 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<T: Encodable>(_ 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() }

Expand Down Expand Up @@ -238,7 +238,7 @@ private class _URLEncodedFormEncoder: Encoder {
mutating func encode(_ value: UInt32) throws { self.encodeResult(value) }
mutating func encode(_ value: UInt64) throws { self.encodeResult(value) }

mutating func encode<T: Encodable>(_ value: T) throws {
mutating func encode(_ value: some Encodable) throws {
self.count += 1

self.encoder.codingPath.append(URLEncodedForm.Key(index: self.count))
Expand Down Expand Up @@ -304,7 +304,7 @@ extension _URLEncodedFormEncoder: SingleValueEncodingContainer {
func encode(_ value: UInt32) throws { self.encodeResult(value) }
func encode(_ value: UInt64) throws { self.encodeResult(value) }

func encode<T: Encodable>(_ value: T) throws {
func encode(_ value: some Encodable) throws {
try value.encode(to: self)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Hummingbird/HTTP/MediaType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public struct HBMediaType: Sendable, CustomStringConvertible {
break
}
}
if let category = category,
let subCategory = subCategory
if let category,
let subCategory
{
self.type = category
self.subType = subCategory.lowercased()
Expand Down
4 changes: 2 additions & 2 deletions Sources/Hummingbird/Storage/MemoryPersistDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public actor HBMemoryPersistDriver<C: Clock>: HBPersistDriver where C.Duration =
self.clock = clock
}

public func create<Object: Codable & Sendable>(key: String, value: Object, expires: Duration?) async throws {
public func create(key: String, value: some Codable & Sendable, expires: Duration?) async throws {
guard self.values[key] == nil else { throw HBPersistError.duplicate }
self.values[key] = .init(value: value, expires: expires.map { self.clock.now.advanced(by: $0) })
}

public func set<Object: Codable & Sendable>(key: String, value: Object, expires: Duration?) async throws {
public func set(key: String, value: some Codable & Sendable, expires: Duration?) async throws {
self.values[key] = .init(value: value, expires: expires.map { self.clock.now.advanced(by: $0) })
}

Expand Down
3 changes: 1 addition & 2 deletions Sources/HummingbirdCore/Server/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ public actor HBServer<ChildChannel: HBChildChannel>: Service {
#endif

do {
let asyncChannel: AsyncServerChannel
switch configuration.address.value {
let asyncChannel = switch configuration.address.value {
case .hostname(let host, let port):
asyncChannel = try await bootstrap.bind(
host: host,
Expand Down
4 changes: 2 additions & 2 deletions Sources/HummingbirdCore/Utils/HBParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct HBParser: Sendable {

/// Create a Parser object
/// - Parameter string: UTF8 data to parse
public init?<Bytes: Collection>(_ utf8Data: Bytes, validateUTF8: Bool = true) where Bytes.Element == UInt8 {
public init?(_ utf8Data: some Collection<UInt8>, validateUTF8: Bool = true) {
if let buffer = utf8Data as? [UInt8] {
self.buffer = buffer
} else {
Expand Down Expand Up @@ -663,7 +663,7 @@ extension Unicode.Scalar {
}
}

extension Set where Element == Unicode.Scalar {
extension Set<Unicode.Scalar> {
public init(_ string: String) {
self = Set(string.unicodeScalars)
}
Expand Down
18 changes: 9 additions & 9 deletions Tests/HummingbirdTests/TestTracer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ final class TestTracer: LegacyTracer {
private(set) var spans = [TestSpan]()
var onEndSpan: (TestSpan) -> Void = { _ in }

func startAnySpan<Instant: TracerInstant>(
func startAnySpan(
_ operationName: String,
context: @autoclosure () -> ServiceContext,
ofKind kind: SpanKind,
at instant: @autoclosure () -> Instant,
at instant: @autoclosure () -> some TracerInstant,
function: String,
file fileID: String,
line: UInt
Expand Down Expand Up @@ -79,11 +79,11 @@ final class TestTracer: LegacyTracer {

#if swift(>=5.7.0)
extension TestTracer: Tracer {
func startSpan<Instant: TracerInstant>(
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
Expand Down Expand Up @@ -161,9 +161,9 @@ final class TestSpan: Span {

let onEnd: (TestSpan) -> Void

init<Instant: TracerInstant>(
init(
operationName: String,
at instant: Instant,
at instant: some TracerInstant,
context: ServiceContext,
kind: SpanKind,
onEnd: @escaping (TestSpan) -> Void
Expand All @@ -188,15 +188,15 @@ final class TestSpan: Span {
self.events.append(event)
}

func recordError<Instant: TracerInstant>(
func recordError(
_ error: Error,
attributes: SpanAttributes,
at instant: @autoclosure () -> Instant
at instant: @autoclosure () -> some TracerInstant
) {
self.recordedErrors.append((error, attributes))
}

func end<Instant: TracerInstant>(at instant: @autoclosure () -> Instant) {
func end(at instant: @autoclosure () -> some TracerInstant) {
self.endTime = instant().millisecondsSinceEpoch
self.onEnd(self)
}
Expand Down

0 comments on commit 37a59af

Please sign in to comment.