i feel like this should really work:
public
protocol BSONEncoder
{
static
var type:BSON { get }
static
func move(_:consuming BSON.Output<[UInt8]>) -> Self
consuming
func move() -> BSON.Output<[UInt8]>
}
alas, i seem to be running into a compiler bug:
extension BSON.Output<[UInt8]>
{
public
subscript<Encoder>(as _:Encoder.Type) -> Encoder
where Encoder:BSONEncoder
{
_read
{
let encoder:Encoder = .move(self)
yield encoder
}
_modify
{
var encoder:Encoder = .move(consume self)
defer { self = (consume encoder).move() }
yield &encoder
}
}
}
/swift/swift-mongodb/Sources/BSONStreaming/BSON.Output.swift:243:37:
error: 'consume' applied to value that the compiler does not support.
This is a compiler bug. Please file a bug with a small example of
the bug
defer { self = (consume encoder).move() }
^
error: fatalError
any better ways to move a buffer back to its original location in a defer
statement, without unnecessarily refcounting?