MCPcopy Create free account
hub / github.com/bedroombuilds/python2rust / main

Function main

05_functions/rust/closures.rs:1–23  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1fn main() {
2 let example_closure = |x| x;
3
4 let s = example_closure(String::from("hello"));
5 let n = example_closure(5);
6 println!("{} {}", s, n);
7
8 let x = vec![1, 2, 3];
9
10 let equal_to_x = move |z| z == x;
11
12 println!("this is x {:?}", x);
13 let y = vec![1, 2, 3];
14 assert!(equal_to_x(y));
15
16 let items: Vec<i32> = vec![1, 2, 3, 4, 5];
17 let plus_one: Vec<_> = items.iter().map(|x| x + 1).collect();
18 let sum_all: i32 = items.iter().map(|x| x + 1).sum();
19 println!("{:?} {}", plus_one, sum_all);
20
21 let two_args = |x, y| x - y;
22 println!("{}", two_args(5, 3));
23}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected