Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge redundant document types #121

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
restore lost collection-typed initializers for Array, Set, Dictionary…
…, OrderedDictionary
  • Loading branch information
tayloraswift committed Feb 6, 2024
commit 740ad1b7596f2a6faf81a3150315ae90c4e4d83f
9 changes: 6 additions & 3 deletions Sources/BSONDecoding/Array (ext).swift
Original file line number Diff line number Diff line change
@@ -3,10 +3,13 @@ extension Array:BSONDecodable where Element:BSONDecodable
@inlinable public
init(bson:BSON.AnyValue) throws
{
let list:BSON.List = try .init(bson: consume bson)

try self.init(bson: try .init(bson: consume bson))
}
@inlinable public
init(bson:BSON.List) throws
{
self.init()
try list.parse
try bson.parse
{
self.append(try $0.decode(to: Element.self))
}
11 changes: 7 additions & 4 deletions Sources/BSONDecoding/Dictionary (ext).swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
extension Dictionary:BSONDecodable where Key == BSON.Key, Value:BSONDecodable
{
@inlinable public
init(bson:BSON.AnyValue) throws
{
try self.init(bson: try .init(bson: consume bson))
}
/// Decodes an unordered dictionary from the given document. Dictionaries
/// are not ``BSONEncodable``, because round-tripping them loses the field
/// ordering information.
@inlinable public
init(bson:BSON.AnyValue) throws
init(bson:BSON.Document) throws
{
let document:BSON.Document = try .init(bson: consume bson)

self.init()
try document.parse
try bson.parse
{
(field:BSON.FieldDecoder<BSON.Key>) in

9 changes: 6 additions & 3 deletions Sources/BSONDecoding/Extensions/Set (ext).swift
Original file line number Diff line number Diff line change
@@ -3,10 +3,13 @@ extension Set:BSONDecodable where Element:BSONDecodable
@inlinable public
init(bson:BSON.AnyValue) throws
{
let list:BSON.List = try .init(bson: consume bson)

try self.init(bson: try .init(bson: consume bson))
}
@inlinable public
init(bson:BSON.List) throws
{
self.init()
try list.parse
try bson.parse
{
self.update(with: try $0.decode(to: Element.self))
}
9 changes: 6 additions & 3 deletions Sources/BSON_OrderedCollections/OrderedDictionary (ext).swift
Original file line number Diff line number Diff line change
@@ -6,10 +6,13 @@ extension OrderedDictionary:BSONDecodable where Key == BSON.Key, Value:BSONDecod
@inlinable public
init(bson:BSON.AnyValue) throws
{
let document:BSON.Document = try .init(bson: consume bson)

try self.init(bson: try .init(bson: consume bson))
}
@inlinable public
init(bson:BSON.Document) throws
{
self.init()
try document.parse
try bson.parse
{
(field:BSON.FieldDecoder<BSON.Key>) in

Loading