File: letsref.rs

package info (click to toggle)
rust-enclose 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176 kB
  • sloc: makefile: 4
file content (22 lines) | stat: -rw-r--r-- 450 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use enclose::enclose;

fn main() {
	let mut clone_data = 2;
	my_enclose(enclose!((ref clone_data => mut ref_clone_data) || {
		// (ref clone_data => mut ref_clone_data) ->
		// let ref mut ref_clone_data = clone_data;

		println!("#0 {:?}", ref_clone_data);
		*ref_clone_data += 2;
		println!("#1 {:?}", clone_data);

		assert_eq!(clone_data, 4);
	}));

	assert_eq!(clone_data, 4);
}

#[inline]
fn my_enclose<F: FnOnce() -> R, R>(a: F) -> R {
	a()
}