Expand description
A channel for sending borrows. This is useful when you want to borrow data but cannot accept a reference to it via function arguments. For example, because a closure is called by code you do not control and which is unaware of the borrowing.
A reference can be inserted via lend. While the function passed to lend executes, the reference can be reborrowed using borrow. If lend attempts to return while the data is still borrowed, the program is aborted.
let channel = Rc::new(BorrowChannel::<&i32, _>::new_unsync());
let mut_channel = Rc::new(BorrowChannel::<&mut i32, _>::new_unsync());
let reads_a = || {
assert_eq!(42, *channel.borrow().get_mut());
};
let writes_a = || *mut_channel.borrow().get_mut() = 42;
let mut a = 0;
mut_channel.lend(&mut a, writes_a);
channel.lend(&mut a, reads_a);Structs§
- Borrow
Channel - A channel for sending borrows.
- Borrow
Channel Guard - Returned from borrow.
- Sync
Lock - Used in a BorrowChannel that supports access from multiple threads.
- Unsync
Lock - Used in a BorrowChannel that does not support access from multiple threads.
Traits§
- Lock
- A type parameter on BorrowChannel that describes the synchronization strategy.
- Reborrowable
- A type that can be used with BorrowChannel.