-
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 #134 from tayloraswift/convert-let
convert LetDocument to LetEncoder
- Loading branch information
Showing
11 changed files
with
147 additions
and
86 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
55 changes: 55 additions & 0 deletions
55
Sources/MongoBuiltins/Documents/Let/Mongo.LetEncoder.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,55 @@ | ||
import BSON | ||
import MongoABI | ||
|
||
extension Mongo | ||
{ | ||
@frozen public | ||
struct LetEncoder:Sendable | ||
{ | ||
@usableFromInline | ||
var bson:BSON.DocumentEncoder<BSON.Key> | ||
|
||
@inlinable internal | ||
init(bson:BSON.DocumentEncoder<BSON.Key>) | ||
{ | ||
self.bson = bson | ||
} | ||
} | ||
} | ||
extension Mongo.LetEncoder:BSON.Encoder | ||
{ | ||
@inlinable public | ||
init(_ output:consuming BSON.Output) | ||
{ | ||
self.init(bson: .init(output)) | ||
} | ||
|
||
@inlinable public consuming | ||
func move() -> BSON.Output { self.bson.move() } | ||
|
||
@inlinable public static | ||
var frame:BSON.DocumentFrame { .document } | ||
} | ||
extension Mongo.LetEncoder | ||
{ | ||
@inlinable public | ||
subscript(`let` binding:Mongo.Variable<some Any>, | ||
yield:(inout Mongo.ExpressionEncoder) -> ()) -> Void | ||
{ | ||
mutating get | ||
{ | ||
yield(&self.bson[with: binding.name][as: Mongo.ExpressionEncoder.self]) | ||
} | ||
} | ||
|
||
@inlinable public | ||
subscript<Encodable>(`let` binding:Mongo.Variable<some Any>) -> Encodable? | ||
where Encodable:BSONEncodable | ||
{ | ||
get { nil } | ||
set (value) | ||
{ | ||
value?.encode(to: &self.bson[with: binding.name]) | ||
} | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
Sources/MongoBuiltins/Documents/Merge/Mongo.MergeDocument.Let.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
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
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
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
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