Cairo Closures
Overview
Guide closure syntax and how closures capture environment values in Cairo.
Quick Use
- •Read
references/closures.mdbefore answering. - •Use concise examples like
|x| x * 2and multi-line closures with{}. - •Mention the current limitation on capturing mutable variables.
Response Checklist
- •Use pipe syntax for parameters and infer types when possible.
- •Explain capture of outer bindings and when that affects trait bounds.
- •Choose
FnOnce,FnMut, orFnbased on how the closure uses captured values.
Example Requests
- •"How do I write a closure in Cairo?"
- •"Why is the closure type inferred as
u8?" - •"What is the difference between
FnOnce,FnMut, andFn?"