Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PackageDescription
let extraSettings: [SwiftSetting] = [
.enableExperimentalFeature("SuppressedAssociatedTypes"),
.enableExperimentalFeature("LifetimeDependence"),
.enableExperimentalFeature("Lifetimes"),
.enableUpcomingFeature("LifetimeDependence"),
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
.enableUpcomingFeature("InferIsolatedConformances"),
Expand All @@ -21,7 +22,10 @@ let package = Package(
targets: ["HTTPServer"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-collections.git", from: "1.0.4"),
.package(
url: "https://github.com/FranzBusch/swift-collections.git",
branch: "fb-async"
),
.package(url: "https://github.com/apple/swift-http-types.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-distributed-tracing.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-certificates.git", from: "1.0.4"),
Expand All @@ -48,7 +52,9 @@ let package = Package(
.target(
name: "HTTPServer",
dependencies: [
"AsyncStreaming",
.product(name: "DequeModule", package: "swift-collections"),
.product(name: "BasicContainers", package: "swift-collections"),
.product(name: "X509", package: "swift-certificates"),
.product(name: "HTTPTypes", package: "swift-http-types"),
.product(name: "NIOCore", package: "swift-nio"),
Expand All @@ -71,6 +77,13 @@ let package = Package(
],
swiftSettings: extraSettings
),
.target(
name: "AsyncStreaming",
dependencies: [
.product(name: "BasicContainers", package: "swift-collections")
],
swiftSettings: extraSettings
),
.testTarget(
name: "HTTPServerTests",
dependencies: [
Expand Down
56 changes: 56 additions & 0 deletions Sources/AsyncStreaming/EitherError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift HTTP API Proposal open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift HTTP API Proposal project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift HTTP API Proposal project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

/// An enumeration that represents one of two possible error types.
///
/// ``EitherError`` provides a type-safe way to represent errors that can be one of two distinct
/// error types.
public enum EitherError<First: Error, Second: Error>: Error {
/// An error of the first type.
///
/// The associated value contains the specific error instance of type `First`.
case first(First)

/// An error of the second type.
///
/// The associated value contains the specific error instance of type `Second`.
case second(Second)

/// Throws the underlying error by unwrapping this either error.
///
/// This method extracts and throws the actual error contained within the either error,
/// whether it's the first or second type. This is useful when you need to propagate
/// the original error without the either error wrapper.
///
/// - Throws: The underlying error, either of type `First` or `Second`.
///
/// ## Example
///
/// ```swift
/// do {
/// // Some operation that returns EitherError
/// let result = try await operation()
/// } catch let eitherError as EitherError<NetworkError, ParseError> {
/// try eitherError.unwrap() // Throws the original error
/// }
/// ```
public func unwrap() throws {
switch self {
case .first(let first):
throw first
case .second(let second):
throw second
}
}
}
24 changes: 24 additions & 0 deletions Sources/AsyncStreaming/Internal/InlineArray+convenience.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift HTTP API Proposal open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift HTTP API Proposal project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift HTTP API Proposal project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

@available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *)
extension InlineArray where Element: ~Copyable {
package static func one(value: consuming Element) -> InlineArray<1, Element> {
return InlineArray<1, Element>(first: value) { _ in fatalError() }
}

package static func zero(of elementType: Element.Type = Element.self) -> InlineArray<0, Element> {
return InlineArray<0, Element> { _ in }
}
}
22 changes: 22 additions & 0 deletions Sources/AsyncStreaming/Internal/Optional+SendingTake.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift HTTP API Proposal open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift HTTP API Proposal project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift HTTP API Proposal project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

extension Optional where Wrapped: ~Copyable {
@inlinable
mutating func takeSending() -> sending Self {
let result = consume self
self = nil
return result
}
}
Loading
Loading