@@ -3,7 +3,7 @@ import NIO
33
44/// Iterator over a `BSONDocument`. This type is not meant to be used directly; please use `Sequence` protocol methods
55/// instead.
6- public struct BSONDocumentIterator : IteratorProtocol {
6+ public class BSONDocumentIterator : IteratorProtocol {
77 /// The buffer we are iterating over.
88 private var buffer : ByteBuffer
99 private var exhausted : Bool
@@ -15,12 +15,12 @@ public struct BSONDocumentIterator: IteratorProtocol {
1515 self . buffer. moveReaderIndex ( to: 4 )
1616 }
1717
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)
2020 }
2121
2222 /// 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 ? {
2424 // The only time this would crash is when the document is incorrectly formatted
2525 do {
2626 return try self . nextThrowing ( )
@@ -34,7 +34,7 @@ public struct BSONDocumentIterator: IteratorProtocol {
3434 * - Throws:
3535 * - `InternalError` if the underlying buffer contains invalid BSON
3636 */
37- internal mutating func nextThrowing( ) throws -> BSONDocument . KeyValuePair ? {
37+ internal func nextThrowing( ) throws -> BSONDocument . KeyValuePair ? {
3838 guard self . buffer. readableBytes != 0 else {
3939 // Iteration has been exhausted
4040 guard self . exhausted else {
@@ -88,7 +88,7 @@ public struct BSONDocumentIterator: IteratorProtocol {
8888
8989 /// Finds the key in the underlying buffer, and returns the [startIndex, endIndex) containing the corresponding
9090 /// element.
91- internal mutating func findByteRange( for searchKey: String ) -> Range < Int > ? {
91+ internal func findByteRange( for searchKey: String ) -> Range < Int > ? {
9292 while true {
9393 let startIndex = self . buffer. readerIndex
9494 guard let ( key, _) = self . next ( ) else {
@@ -116,7 +116,7 @@ public struct BSONDocumentIterator: IteratorProtocol {
116116 fatalError ( " endIndex must be >= startIndex " )
117117 }
118118
119- var iter = BSONDocumentIterator ( over: doc)
119+ let iter = BSONDocumentIterator ( over: doc)
120120
121121 var excludedKeys : [ String ] = [ ]
122122
0 commit comments