Struct scope_lock::ExtendedFn
source · pub struct ExtendedFn<I, O> { /* private fields */ }
Implementations§
source§impl<I, O> ExtendedFn<I, O>
impl<I, O> ExtendedFn<I, O>
sourcepub fn call(&self, input: I) -> O
pub fn call(&self, input: I) -> O
Examples found in repository?
examples/references.rs (line 22)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
let mut a = vec![1, 2, 3];
let mut x = 0;
let f1 = &|()| {
println!("hello from the first scoped thread");
// We can borrow `a` here.
dbg!(&a);
};
let f2 = &mut |()| {
println!("hello from the second scoped thread");
// We can even mutably borrow `x` here,
// because no other threads are using it.
x += a[0] + a[2];
};
scope_lock::lock_scope(|e| {
thread::spawn({
let f = e.extend_fn(f1);
move || f.call(())
});
thread::spawn({
let mut f = e.extend_fn_mut(f2);
move || f.call(())
});
println!("hello from the main thread");
});
// After the scope, we can modify and access our variables again:
a.push(4);
assert_eq!(x, a.len());
}
Trait Implementations§
impl<I, O> Send for ExtendedFn<I, O>
impl<I, O> Sync for ExtendedFn<I, O>
Auto Trait Implementations§
impl<I, O> Freeze for ExtendedFn<I, O>
impl<I, O> !RefUnwindSafe for ExtendedFn<I, O>
impl<I, O> Unpin for ExtendedFn<I, O>
impl<I, O> !UnwindSafe for ExtendedFn<I, O>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more