GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing doc.rust-lang.org — Closure expressions - The Rust Reference Closure expressionsSyntax
ClosureParameters → ClosureParam ( , ClosureParam )* ,? ClosureParam → OuterAttribute* PatternNoTopAlt ( : Type )? A closure expression, also known as a lambda expression or a lambda, defines a closure type and evaluates to a value of that type. The syntax for a closure expression is an optional The optional type after each pattern is a type annotation for the pattern. If there is a return type, the closure body must be a block. A closure expression denotes a function that maps a list of parameters onto the expression that follows the parameters. Just like a Each closure expression has a unique, anonymous type. Significantly, closure expressions capture their environment, which regular function definitions do not. Without the If needed the compiler will infer that instead mutable references should be taken, or that the values should be moved or copied (depending on their type) from the environment. A closure can be forced to capture its environment by copying or moving values by prefixing it with the Closure trait implementationsWhich traits the closure type implements depends on how variables are captured, the types of the captured variables, and the presence of Async closuresClosures marked with the Calling the async closure does not perform any work, but instead evaluates to a value that implements
ExampleIn this example, we define a function
Attributes on closure parametersAttributes on closure parameters follow the same rules and restrictions as regular function parameters.
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |