I ran into an issue where I wanted a closure to borrow some data, but could not pass a reference, as the invocation of the function happens in code I do not control. To solve this, I came up with an abstraction that allows sending a borrow from one code site to another. If the providing borrow ends before the using borrow, the program is aborted.
There are a few ways to think about this:
- A channel, through which you send a borrow.
- A RefCell, where data is not owned by the cell, but only lent to it.
- A version of scoped threads, where instead of creating a new thread, the function using the borrowed data runs on the same thread.
As there is some unsafe code in here, I would really appreciate it if you could take some time to look over it. I am particularly uncertain about the soundness of Deref for BorrowChannelGuard
.
Source: View source