-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from tayloraswift/upgrade-swift-bson
upgrade swift-bson dependency
- Loading branch information
Showing
3 changed files
with
51 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
Sources/BSON_OrderedCollections/OrderedDictionary (ext).swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import BSON | ||
import OrderedCollections | ||
|
||
extension OrderedDictionary:@retroactive BSONDecodable | ||
where Key == BSON.Key, Value:BSONDecodable | ||
{ | ||
@inlinable public | ||
init(bson:BSON.AnyValue) throws | ||
{ | ||
try self.init(bson: try .init(bson: consume bson)) | ||
} | ||
@inlinable public | ||
init(bson:BSON.Document) throws | ||
{ | ||
self.init() | ||
try bson.parse | ||
{ | ||
(field:BSON.FieldDecoder<BSON.Key>) in | ||
|
||
if case _? = self.updateValue(try field.decode(to: Value.self), | ||
forKey: field.key) | ||
{ | ||
throw BSON.DocumentKeyError<BSON.Key>.duplicate(field.key) | ||
} | ||
} | ||
} | ||
} | ||
extension OrderedDictionary:@retroactive BSONDocumentEncodable, @retroactive BSONEncodable | ||
where Key == BSON.Key, Value:BSONEncodable | ||
{ | ||
@inlinable public | ||
func encode(to bson:inout BSON.DocumentEncoder<BSON.Key>) | ||
{ | ||
for (key, value):(Key, Value) in self.elements | ||
{ | ||
bson[key] = value | ||
} | ||
} | ||
} |