Crates.io | captures |
lib.rs | captures |
version | 0.1.0 |
source | src |
created_at | 2021-11-26 22:16:38.80546 |
updated_at | 2021-11-26 22:16:38.80546 |
description | Provides macros to express more powerful closure captures |
homepage | |
repository | https://github.com/JakobDegen/captures |
max_upload_size | |
id | 488172 |
size | 47,227 |
This crate provides simple macros letting you express more powerful closure captures. For example, you can capture the clone of a value:
use std::rc::Rc;
let my_val = Rc::new(1);
captures::capture!(clone my_val, move || {
// `my_val` is cloned here!
});
You can also capture arbitrary expressions and override the Edition-2021 capture semantics. Best of all, you can even specify that your closure should not capture any variables outside the ones you've listed:
let a = 1;
let b = 2;
captures::capture_only!(clone a, move || {
a + b // errors: `b` is unknown
})
Consult the full documentation for the details.