docs.rs failed to build capture-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
capture.rs
A macro for adding explicit capture clauses to a (closure-) expression.
Using this macro, it becomes possible to be explicit about what variables a closure captures, and by which capture mode it does so.
Syntax
capture!($([move IDENT,]
[ref IDENT,]
[IDENT IDENT,])*
in EXPR)
Semantic
The macro will expand to nested block expressions with a let
binding per capture clause:
- The
move x
clause rebinds a name by itself, which is effectively a no-op. - The
ref x
clause rebinds a name by a shared reference to it. - The
ref mut x
clause rebinds a name by a mutable reference to it. - The
IDENT x
clause rebinds a name to the result of calling.IDENT()
method on it. This can for example be used to capture by clone, which would look like this:clone x
.
These bindings will be in scope for the final EXPR
expression, which will usually be a
by-value capturing closure.
Current limitations and future changes
- The macro syntax makes it somewhat verbose. A future version of this package might make use of expression-attributes instead to become more lightweight.
- The macro might become more specialized to always produce a by-value capturing closure, rather than allowing arbitrary expressions.
Example
Using the macro:
extern crate capture;