This should work:
public struct Disconnected<Wrapped: ~Copyable>: ~Copyable {
private enum UnderlyingType : ~Copyable {
case some(Wrapped), none
mutating func send() -> Wrapped? {
switch consume self {
case .some(let value):
self = .none
return value
case .none:
self = .none
return nil
}
}
}
private var value: UnderlyingType
public init(_ value: consuming sending Wrapped) { self.value = .some(value) }
public init() { self.value = .none }
public mutating func send() -> sending Wrapped? {
switch self.value.send() {
case .some(let value):
self.value = .none
return value
case .none:
return nil
}
}
}