From 13ec89db9f43795f2e017385fc893e2c0b6fcfef Mon Sep 17 00:00:00 2001 From: Daniel Eggert Date: Sun, 15 Nov 2026 10:35:26 +0100 Subject: [PATCH] Make parse(limit:_:) and withParseInput(_:) internal Their closures take a ParseInput, which has no public members, so they added unusable API to ByteBuffer, DispatchData, Data and [UInt8]. --- Sources/NIOIMAPCore/Bytes/ParserInputBuffer.swift | 9 +++------ Sources/NIOIMAPCore/Parser/ParseInput.swift | 7 +++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Sources/NIOIMAPCore/Bytes/ParserInputBuffer.swift b/Sources/NIOIMAPCore/Bytes/ParserInputBuffer.swift index 48e452fb..43cc5bcc 100644 --- a/Sources/NIOIMAPCore/Bytes/ParserInputBuffer.swift +++ b/Sources/NIOIMAPCore/Bytes/ParserInputBuffer.swift @@ -73,10 +73,7 @@ internal protocol ParserInputBuffer { } /// A ``ParserInputBuffer`` the parser can also consume from, so that a caller does not have to trim -/// it by hand. -/// -/// ``ConsumableParserInputBuffer/parse(limit:_:)`` is the entry point that trims: whatever the -/// parser consumed is discarded when it returns, including when it throws. +/// it by hand: the stream parsers discard whatever they consumed, including when they throw. /// /// - Important: ``discardFirst(_:)`` must be O(1) amortised in the number of bytes discarded. A /// conformer that moves the remaining bytes down instead makes a caller that trims after every @@ -220,7 +217,7 @@ extension ParserInputBuffer { /// default argument here would shadow a conformer's own witness, so a one-pass conformer would /// silently take the generic path whenever the caller left the limit out — which is the common /// case, and the failure is invisible. - public func withParseInput(_ body: (inout ParseInput) throws -> R) rethrows -> R { + internal func withParseInput(_ body: (inout ParseInput) throws -> R) rethrows -> R { try withParseInput(limit: .max, body) } @@ -360,7 +357,7 @@ extension ConsumableParserInputBuffer { /// - limit: The most bytes the parser may consume. /// - body: A closure that reads through the cursor. /// - Returns: Whatever `body` returns. - public mutating func parse( + internal mutating func parse( limit: Int = .max, _ body: (inout ParseInput) throws -> R ) rethrows -> R { diff --git a/Sources/NIOIMAPCore/Parser/ParseInput.swift b/Sources/NIOIMAPCore/Parser/ParseInput.swift index 1b0173f1..47c5b847 100644 --- a/Sources/NIOIMAPCore/Parser/ParseInput.swift +++ b/Sources/NIOIMAPCore/Parser/ParseInput.swift @@ -161,10 +161,9 @@ internal func _span(_ bytes: UnsafeBufferPointer) -> Span { /// /// If you are looking for how to give the parser bytes, you want ``ParserInputBuffer`` — in a /// connection, ``IMAPInputBuffer``. `ParseInput` is `public` for one reason only: it appears in the -/// closure signature of ``ParserInputBuffer/withParseInput(limit:_:)`` and -/// ``ConsumableParserInputBuffer/parse(limit:_:)``, which a caller outside this module has to be able -/// to spell in order to conform. Everything that *reads* through a cursor — both initialisers, every -/// primitive, every combinator, and the read position itself — is `internal`. +/// closure signature of ``ParserInputBuffer/withParseInput(limit:_:)``, which a caller outside this +/// module has to be able to spell in order to conform. Everything that *reads* through a cursor — both +/// initialisers, every primitive, every combinator, and the read position itself — is `internal`. /// /// So there is nothing a client can do with one, and nothing it needs to do: no public API takes a /// cursor. ``CommandParser/parseCommandStream(buffer:)`` and