We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4fcaef9 commit a590d0bCopy full SHA for a590d0b
rust/src/main.rs
@@ -309,6 +309,25 @@ fn macro_test() {
309
assert_eq!(sample_macro!(1, 2), 3);
310
}
311
312
+#[test]
313
+fn closue() {
314
+ // Closures are like lambda expressions in C++
315
+
316
+ // Closures can capture external objects (constants, variables)
317
+ let one = 1;
318
319
+ // Closure which is bound to reference (name)
320
+ let closure_annotated = |arg: i32| -> i32 { arg + one };
321
+ assert_eq!(closure_annotated(1), 2);
322
323
+ // Annotation and block are optional
324
+ let closure_inferred = |arg| arg + one;
325
+ assert_eq!(closure_inferred(1), 2);
326
327
+ // anonymous closure
328
+ assert_eq!((|arg| arg + one)(1), 2);
329
+}
330
331
#[test]
332
#[ignore]
333
fn failing_test() {
0 commit comments