@@ -3,7 +3,7 @@ import NIO
3
3
4
4
/// Iterator over a `BSONDocument`. This type is not meant to be used directly; please use `Sequence` protocol methods
5
5
/// instead.
6
- public struct BSONDocumentIterator : IteratorProtocol {
6
+ public class BSONDocumentIterator : IteratorProtocol {
7
7
/// The buffer we are iterating over.
8
8
private var buffer : ByteBuffer
9
9
private var exhausted : Bool
@@ -15,12 +15,12 @@ public struct BSONDocumentIterator: IteratorProtocol {
15
15
self . buffer. moveReaderIndex ( to: 4 )
16
16
}
17
17
18
- internal init ( over doc: BSONDocument ) {
19
- self = BSONDocumentIterator ( over: doc. buffer)
18
+ internal convenience init ( over doc: BSONDocument ) {
19
+ self . init ( over: doc. buffer)
20
20
}
21
21
22
22
/// Advances to the next element and returns it, or nil if no next element exists.
23
- public mutating func next( ) -> BSONDocument . KeyValuePair ? {
23
+ public func next( ) -> BSONDocument . KeyValuePair ? {
24
24
// The only time this would crash is when the document is incorrectly formatted
25
25
do {
26
26
return try self . nextThrowing ( )
@@ -34,7 +34,7 @@ public struct BSONDocumentIterator: IteratorProtocol {
34
34
* - Throws:
35
35
* - `InternalError` if the underlying buffer contains invalid BSON
36
36
*/
37
- internal mutating func nextThrowing( ) throws -> BSONDocument . KeyValuePair ? {
37
+ internal func nextThrowing( ) throws -> BSONDocument . KeyValuePair ? {
38
38
guard self . buffer. readableBytes != 0 else {
39
39
// Iteration has been exhausted
40
40
guard self . exhausted else {
@@ -88,7 +88,7 @@ public struct BSONDocumentIterator: IteratorProtocol {
88
88
89
89
/// Finds the key in the underlying buffer, and returns the [startIndex, endIndex) containing the corresponding
90
90
/// element.
91
- internal mutating func findByteRange( for searchKey: String ) -> Range < Int > ? {
91
+ internal func findByteRange( for searchKey: String ) -> Range < Int > ? {
92
92
while true {
93
93
let startIndex = self . buffer. readerIndex
94
94
guard let ( key, _) = self . next ( ) else {
@@ -116,7 +116,7 @@ public struct BSONDocumentIterator: IteratorProtocol {
116
116
fatalError ( " endIndex must be >= startIndex " )
117
117
}
118
118
119
- var iter = BSONDocumentIterator ( over: doc)
119
+ let iter = BSONDocumentIterator ( over: doc)
120
120
121
121
var excludedKeys : [ String ] = [ ]
122
122
0 commit comments