Skip to content

Commit

Permalink
Make HTMLStreamWriter.write mutating (#23)
Browse files Browse the repository at this point in the history
adjust example to fix hummingbird-rc.5 breaking changes
  • Loading branch information
sliemeobn authored Aug 28, 2024
1 parent 1b2ee89 commit 7215231
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Examples/HummingbirdDemo/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
.executable(name: "App", targets: ["App"]),
],
dependencies: [
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0-beta.6"),
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0-rc.5"),
.package(path: "../../"),
],
targets: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Hummingbird
extension MainLayout: ResponseGenerator {}

struct HTMLResponseBodyWriter: HTMLStreamWriter {
func write(_ bytes: ArraySlice<UInt8>) async throws {
mutating func write(_ bytes: ArraySlice<UInt8>) async throws {
try await writer.write(allocator.buffer(bytes: bytes))
}

Expand All @@ -18,7 +18,8 @@ extension HTML where Self: Sendable {
status: .ok,
headers: [.contentType: "text/html; charset=utf-8"],
body: .init { [self] writer in
try await self.render(into: HTMLResponseBodyWriter(allocator: context.allocator, writer: writer))
try await self.render(into: HTMLResponseBodyWriter(allocator: ByteBufferAllocator(), writer: writer))
try await writer.finish(nil)
}
)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Elementary/Html+Rendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ public extension HTML {
/// Conform to this protocol to stream HTML responses efficiently.
public protocol HTMLStreamWriter {
/// Writes a chunk of rendered HTML.
func write(_ bytes: ArraySlice<UInt8>) async throws
mutating func write(_ bytes: ArraySlice<UInt8>) async throws
}

0 comments on commit 7215231

Please sign in to comment.