I was playing around with non escapable types and am running into this error:
struct Foo: ~Copyable, ~Escapable {
}
struct FooData: ~Copyable, ~Escapable {
@_lifetime(borrow foo)
fileprivate init(foo: borrowing Foo) {
}
}
struct FooDataContainer: ~Copyable, ~Escapable {
@_lifetime(borrow data)
init(
data: borrowing FooData
) {
}
}
@_lifetime(borrow foo)
func process1(_ foo: borrowing Foo) -> FooData {
return FooData(foo: foo)
}
@_lifetime(borrow foo)
func process2(_ foo: borrowing Foo) -> FooDataContainer {
// ERROR: Lifetime-dependent value escapes its scope
return FooDataContainer(data: FooData(foo: foo))
}
I'm guessing this is because FooData only exists in the body of process2, but what I'm really trying to express is that FooDataContainer should have a lifetime that is the borrow of foo. Is there a way to pass this data from FooData to FooDataContainer? Is there another way to implement this pattern?