Debian Codegraph @

tests/enc.rs

raw symbols SCIP
1 use encloserust-analyzer cargo enclose 1.2.1 crate/::encrust-analyzer cargo enclose 1.2.1 enclose!;
2 use encloserust-analyzer cargo enclose 1.2.1 crate/::encloserust-analyzer cargo enclose 1.2.1 enclose!;
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#;
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::MutexGuardrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/MutexGuard#;
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::RwLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/rwlock/RwLock#;
7 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/;
8
9 struct MutexSafeDatarust-analyzer cargo enclose 1.2.1 MutexSafeData#(Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#<usize>);
10
11 impl MutexSafeDatarust-analyzer cargo enclose 1.2.1 MutexSafeData# {
12 #[inline]
13 pub fn newrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]new().(def: usize) -> Selfrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData] {
14 MutexSafeDatarust-analyzer cargo enclose 1.2.1 MutexSafeData#(Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]new().(def))
15 }
16 #[allow(dead_code)]
17 #[inline]
18 pub fn setrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]set().(&self, size: usize) {
19 *rust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`MutexGuard<'_, T>`][DerefMut]deref_mut().self.get_mutrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]get_mut().() = size;
20 }
21 #[allow(dead_code)]
22 #[inline]
23 pub fn addrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]add().(&self, size: usize) {
24 *rust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`MutexGuard<'_, T>`][DerefMut]deref_mut().self.get_mutrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]get_mut().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().size;
25 }
26 #[inline]
27 pub fn get_mutrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]get_mut().(&self) -> MutexGuardrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/MutexGuard#<usize> {
28 match self.0rust-analyzer cargo enclose 1.2.1 MutexSafeData#0..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().() {
29 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(a) => a,
30 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => e.into_innerrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/impl#[`PoisonError<T>`]into_inner().(),
31 }
32 }
33 }
34
35 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
36 fn clone_enc_macrosrust-analyzer cargo enclose 1.2.1 clone_enc_macros().() {
37 let mutex_data = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(MutexSafeDatarust-analyzer cargo enclose 1.2.1 MutexSafeData#::newrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]new().(0));
38 let mutex_data2 = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(MutexSafeDatarust-analyzer cargo enclose 1.2.1 MutexSafeData#::newrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]new().(0));
39
40 // one value
41 encrust-analyzer cargo enclose 1.2.1 enclose!!(
42 (mutex_data) || {
43 mutex_data.addrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]add().(1);
44 }
45 )();
46
47 // two value
48 encrust-analyzer cargo enclose 1.2.1 enclose!!(
49 (mutex_data, mutex_data2) || {
50 mutex_data.addrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]add().(1);
51 mutex_data2.addrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]add().(1);
52 }
53 )();
54
55 // one alias
56 encrust-analyzer cargo enclose 1.2.1 enclose!!((mutex_data => m1) || {
57 m1.addrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]add().(1);
58 })();
59
60 // two alias
61 encrust-analyzer cargo enclose 1.2.1 enclose!!((mutex_data => m1, mutex_data2 => m2) || {
62 m1.addrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]add().(1);
63 m2.addrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]add().(1);
64 })();
65
66 // combination
67 encrust-analyzer cargo enclose 1.2.1 enclose!!((mutex_data, mutex_data2 => m2) || {
68 mutex_data.addrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]add().(1);
69 m2.addrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]add().(1);
70 })();
71
72 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(*rust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`MutexGuard<'_, T>`][Deref]deref().mutex_data.get_mutrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]get_mut().(), 5);
73 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(*rust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`MutexGuard<'_, T>`][Deref]deref().mutex_data2.get_mutrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]get_mut().(), 3);
74 }
75
76 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
77 fn test_unk_operationsrust-analyzer cargo enclose 1.2.1 test_unk_operations().() {
78 let mutex_data = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(MutexSafeDatarust-analyzer cargo enclose 1.2.1 MutexSafeData#::newrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]new().(0));
79 let mutex_data2 = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(MutexSafeDatarust-analyzer cargo enclose 1.2.1 MutexSafeData#::newrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]new().(0));
80
81 // one
82 encrust-analyzer cargo enclose 1.2.1 enclose!!((@mutex_data.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().() => m1) || {
83 m1.addrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]add().(1);
84 })();
85
86 // two
87 encrust-analyzer cargo enclose 1.2.1 enclose!!((@mutex_data.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().() => m1, @mutex_data2.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().() => m2) || {
88 m1.addrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]add().(1);
89 m2.addrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]add().(1);
90 })();
91
92 // unk operations
93 encrust-analyzer cargo enclose 1.2.1 enclose!!((@{ mutex_data2.setrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]set().(1); mutex_data2.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().() } => m2) || {
94 m2.addrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]add().(1);
95 })();
96
97 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(*rust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`MutexGuard<'_, T>`][Deref]deref().mutex_data.get_mutrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]get_mut().(), 2);
98 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(*rust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`MutexGuard<'_, T>`][Deref]deref().mutex_data2.get_mutrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]get_mut().(), 2);
99 }
100
101 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
102 fn threadpool_twovalue_and_aliasrust-analyzer cargo enclose 1.2.1 threadpool_twovalue_and_alias().() {
103 let v1 = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(MutexSafeDatarust-analyzer cargo enclose 1.2.1 MutexSafeData#::newrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]new().(1));
104 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(*rust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`MutexGuard<'_, T>`][Deref]deref().v1.get_mutrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]get_mut().(), 1);
105
106 let v2 = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(RwLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/rwlock/RwLock#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/rwlock/impl#[`RwLock<T>`]new().((0, 2, 3, 4)));
107
108 let count_thread = 5;
109 let mut join_all = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(count_thread);
110
111 for _a in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#count_thread {
112 join_all.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().({
113 threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::spawnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/spawn().(encloserust-analyzer cargo enclose 1.2.1 enclose!!((v1, v2, count_thread => alias_cthreads,) move || {
114 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(alias_cthreads, 5);
115
116 *rust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`MutexGuard<'_, T>`][DerefMut]deref_mut().v1.get_mutrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]get_mut().() += 1;
117
118 let mut lock_v2 = match v2.writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/rwlock/impl#[`RwLock<T>`]write().() {
119 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(a) => a,
120 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => e.into_innerrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/impl#[`PoisonError<T>`]into_inner().(),
121 };
122 lock_v2.0 += 1;
123 }))
124 });
125 }
126 for a in join_all {
127 a.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/join_handle/impl#[`JoinHandle<T>`]join().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
128 }
129 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(*rust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`MutexGuard<'_, T>`][Deref]deref().v1.get_mutrust-analyzer cargo enclose 1.2.1 impl#[MutexSafeData]get_mut().(), 6);
130 {
131 let lock_v2 = match v2.writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/rwlock/impl#[`RwLock<T>`]write().() {
132 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(a) => a,
133 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => e.into_innerrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/impl#[`PoisonError<T>`]into_inner().(),
134 };
135 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(lock_v2.0, 5);
136 }
137 }
138
139 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
140 fn selfaliasrust-analyzer cargo enclose 1.2.1 selfalias().() {
141 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:)]
142 struct CheckDatarust-analyzer cargo enclose 1.2.1 CheckData# {
143 arust-analyzer cargo enclose 1.2.1 CheckData#a.: u32,
144 }
145
146 impl CheckDatarust-analyzer cargo enclose 1.2.1 CheckData# {
147 #[inline]
148 pub const fn newrust-analyzer cargo enclose 1.2.1 impl#[CheckData]new().(a: u32) -> Selfrust-analyzer cargo enclose 1.2.1 impl#[CheckData] {
149 Selfrust-analyzer cargo enclose 1.2.1 impl#[CheckData] { arust-analyzer cargo enclose 1.2.1 CheckData#a. }
150 }
151
152 pub fn calculaterust-analyzer cargo enclose 1.2.1 impl#[CheckData]calculate().(&self, mul_num: &u32) -> u32 {
153 encrust-analyzer cargo enclose 1.2.1 enclose!!((*mul_num, self.arust-analyzer cargo enclose 1.2.1 CheckData#a. => mut num0,) move || {
154 // (*mul_num, self.a => mut num0) ->
155 // let mul_num = *mul_num;
156 // let num0 = self.a.clone();
157
158 num0 *= mul_num;
159 num0 += 1024;
160
161 num0
162 })()
163
164 // run_enclose
165 //
166 // let mut enclose = $crate::enclose!( $($tt)* );
167 // enclose()
168 }
169 }
170
171 let data = CheckDatarust-analyzer cargo enclose 1.2.1 CheckData#::newrust-analyzer cargo enclose 1.2.1 impl#[CheckData]new().(1024);
172
173 // (data.a * 2) + 1024
174 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.calculaterust-analyzer cargo enclose 1.2.1 impl#[CheckData]calculate().(&2), 3072);
175
176 // check data
177 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.arust-analyzer cargo enclose 1.2.1 CheckData#a., 1024);
178 }