qubit_function/lib.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026.
4 * Haixing Hu, Qubit Co. Ltd.
5 *
6 * All rights reserved.
7 *
8 ******************************************************************************/
9//! # Qubit Function
10//!
11//! Provides functional programming abstractions for Rust, including:
12//!
13//! - **Transformer types**: Transform values from type T to type R
14//! - **UnaryOperator types**: Transform values of type T to the same type T
15//! - **BiTransformer types**: Transform two values to produce a result
16//! - **BinaryOperator types**: Transform two values of type T to produce a T
17//! - **StatefulBinaryOperator types**: Stateful transform two values of type T to produce a T
18//! - **Consumer types**: Functions that consume values without returning
19//! - **BiConsumer types**: Functions that consume two values without returning
20//! - **Predicate types**: Functions that test values and return boolean
21//! - **BiPredicate types**: Functions that test two values and return boolean
22//! - **Supplier types**: Functions that produce values without input
23//! - **Task types**: Fallible zero-argument and mutable-input actions and computations
24//! - **Mapper types**: Stateful transformations from type T to type R
25//! - **Tester types**: Functions that test conditions without input
26//! - **Comparator types**: Functions that compare values and return ordering
27//!
28//! # Author
29//!
30//! Haixing Hu
31
32// Module declarations
33pub mod comparator;
34pub mod consumers;
35pub mod functions;
36pub mod macros;
37pub mod mutators;
38pub mod predicates;
39pub mod suppliers;
40pub mod tasks;
41pub mod tester;
42pub mod transformers;
43
44// Re-export all types from submodules for backward compatibility
45// Types are organized by functionality and ownership model for better readability
46
47// =============================================================================
48// Core Functional Types
49// =============================================================================
50
51// ---- Consumer Types (Fn(&T)) ----
52pub use consumers::{
53 // Arc-based (shared multi-threaded ownership)
54 ArcConsumer,
55 ArcStatefulConsumer,
56
57 // Box-based (single ownership)
58 BoxConsumer,
59 BoxConsumerOnce,
60 BoxStatefulConsumer,
61
62 // Core traits
63 Consumer,
64 ConsumerOnce,
65 FnConsumerOnceOps,
66 // Extension traits
67 FnConsumerOps,
68 FnStatefulConsumerOps,
69 // Rc-based (shared single-threaded ownership)
70 RcConsumer,
71 RcStatefulConsumer,
72
73 StatefulConsumer,
74};
75
76// ---- BiConsumer Types (Fn(&T, &U)) ----
77pub use consumers::{
78 // Arc-based (shared multi-threaded ownership)
79 ArcBiConsumer,
80 ArcStatefulBiConsumer,
81
82 // Core traits
83 BiConsumer,
84 BiConsumerOnce,
85 // Box-based (single ownership)
86 BoxBiConsumer,
87 BoxBiConsumerOnce,
88 BoxStatefulBiConsumer,
89
90 FnBiConsumerOnceOps,
91 // Extension traits
92 FnBiConsumerOps,
93 FnStatefulBiConsumerOps,
94 // Rc-based (shared single-threaded ownership)
95 RcBiConsumer,
96 RcStatefulBiConsumer,
97
98 StatefulBiConsumer,
99};
100
101// ---- Function Types (Fn(&T) -> R) ----
102pub use functions::{
103 // Arc-based (shared multi-threaded ownership)
104 ArcFunction,
105 ArcMutatingFunction,
106 ArcStatefulFunction,
107 ArcStatefulMutatingFunction,
108
109 // Box-based (single ownership)
110 BoxFunction,
111 BoxFunctionOnce,
112 BoxMutatingFunction,
113 BoxMutatingFunctionOnce,
114 BoxStatefulFunction,
115 BoxStatefulMutatingFunction,
116
117 FnFunctionOnceOps,
118 // Extension traits
119 FnFunctionOps,
120 FnMutatingFunctionOnceOps,
121 FnMutatingFunctionOps,
122 FnStatefulFunctionOps,
123 FnStatefulMutatingFunctionOps,
124 // Core traits
125 Function,
126 FunctionOnce,
127 MutatingFunction,
128 MutatingFunctionOnce,
129 // Rc-based (shared single-threaded ownership)
130 RcFunction,
131 RcMutatingFunction,
132 RcStatefulFunction,
133 RcStatefulMutatingFunction,
134
135 StatefulFunction,
136 StatefulMutatingFunction,
137};
138
139// ---- BiFunction Types (Fn(&T, &U) -> R) ----
140pub use functions::{
141 // Arc-based (shared multi-threaded ownership)
142 ArcBiFunction,
143 ArcBiMutatingFunction,
144
145 // Core traits
146 BiFunction,
147 BiFunctionOnce,
148 BiMutatingFunction,
149 BiMutatingFunctionOnce,
150
151 // Box-based (single ownership)
152 BoxBiFunction,
153 BoxBiFunctionOnce,
154 BoxBiMutatingFunction,
155 BoxBiMutatingFunctionOnce,
156
157 FnBiFunctionOnceOps,
158 // Extension traits
159 FnBiFunctionOps,
160 FnBiMutatingFunctionOnceOps,
161 FnBiMutatingFunctionOps,
162 // Rc-based (shared single-threaded ownership)
163 RcBiFunction,
164 RcBiMutatingFunction,
165};
166
167// ---- Binary Function Types (Fn(&T, &T) -> R) ----
168pub use functions::{
169 // Arc-based (shared multi-threaded ownership)
170 ArcBinaryFunction,
171 ArcBinaryMutatingFunction,
172 // Box-based (single ownership)
173 BoxBinaryFunction,
174 BoxBinaryMutatingFunction,
175
176 // Rc-based (shared single-threaded ownership)
177 RcBinaryFunction,
178 RcBinaryMutatingFunction,
179};
180
181// ---- Conditional Function Types ----
182pub use functions::{
183 ArcConditionalBiFunction,
184 ArcConditionalBiMutatingFunction,
185 // Arc-based (shared multi-threaded ownership)
186 ArcConditionalFunction,
187 ArcConditionalStatefulFunction,
188 BoxConditionalBiFunction,
189 BoxConditionalBiMutatingFunction,
190 BoxConditionalBiMutatingFunctionOnce,
191
192 // Box-based (single ownership)
193 BoxConditionalFunction,
194 BoxConditionalStatefulFunction,
195 RcConditionalBiFunction,
196 RcConditionalBiMutatingFunction,
197
198 // Rc-based (shared single-threaded ownership)
199 RcConditionalFunction,
200 RcConditionalStatefulFunction,
201};
202
203// =============================================================================
204// Data Processing Types
205// =============================================================================
206
207// ---- Transformer Types (Fn(T) -> R) ----
208pub use transformers::{
209 ArcStatefulBiTransformer,
210
211 ArcStatefulTransformer,
212 // Arc-based (shared multi-threaded ownership)
213 ArcTransformer,
214 BoxStatefulBiTransformer,
215
216 BoxStatefulTransformer,
217 // Box-based (single ownership)
218 BoxTransformer,
219 BoxTransformerOnce,
220 FnStatefulBiTransformerOps,
221 FnStatefulTransformerOps,
222 FnTransformerOnceOps,
223 // Extension traits
224 FnTransformerOps,
225 RcStatefulBiTransformer,
226
227 RcStatefulTransformer,
228 // Rc-based (shared single-threaded ownership)
229 RcTransformer,
230 StatefulBiTransformer,
231
232 StatefulTransformer,
233 // Core traits
234 Transformer,
235 TransformerOnce,
236};
237
238// ---- BiTransformer Types (Fn(T, U) -> R) ----
239pub use transformers::{
240 // Arc-based (shared multi-threaded ownership)
241 ArcBiTransformer,
242
243 // Core traits
244 BiTransformer,
245 BiTransformerOnce,
246
247 // Box-based (single ownership)
248 BoxBiTransformer,
249 BoxBiTransformerOnce,
250
251 FnBiTransformerOnceOps,
252 // Extension traits
253 FnBiTransformerOps,
254 // Rc-based (shared single-threaded ownership)
255 RcBiTransformer,
256};
257
258// ---- Operator Types ----
259// Binary operators (Fn(T, T) -> T)
260pub use transformers::{
261 ArcBinaryOperator,
262 BinaryOperator,
263 BinaryOperatorOnce,
264 BoxBinaryOperator,
265 BoxBinaryOperatorOnce,
266 RcBinaryOperator,
267};
268
269// Stateful binary operators (FnMut(T, T) -> T)
270pub use transformers::{
271 ArcStatefulBinaryOperator,
272 BoxStatefulBinaryOperator,
273 RcStatefulBinaryOperator,
274 StatefulBinaryOperator,
275};
276
277// Unary operators (Fn(T) -> T)
278pub use transformers::{
279 ArcUnaryOperator,
280 BoxUnaryOperator,
281 BoxUnaryOperatorOnce,
282 RcUnaryOperator,
283 UnaryOperator,
284 UnaryOperatorOnce,
285};
286
287// ---- Conditional Transformer Types ----
288pub use transformers::{
289 ArcConditionalStatefulBiTransformer,
290 ArcConditionalStatefulTransformer,
291 // Arc-based (shared multi-threaded ownership)
292 ArcConditionalTransformer,
293 BoxConditionalStatefulBiTransformer,
294
295 BoxConditionalStatefulTransformer,
296 // Box-based (single ownership)
297 BoxConditionalTransformer,
298 BoxConditionalTransformerOnce,
299 RcConditionalStatefulBiTransformer,
300
301 RcConditionalStatefulTransformer,
302 // Rc-based (shared single-threaded ownership)
303 RcConditionalTransformer,
304};
305
306// =============================================================================
307// Utility Types
308// =============================================================================
309
310// ---- Mutator Types (Fn(&mut T)) ----
311pub use mutators::{
312 ArcConditionalMutator,
313 ArcConditionalStatefulMutator,
314
315 // Arc-based (shared multi-threaded ownership)
316 ArcMutator,
317 ArcStatefulMutator,
318
319 // Conditional types
320 BoxConditionalMutator,
321 BoxConditionalMutatorOnce,
322 BoxConditionalStatefulMutator,
323 // Box-based (single ownership)
324 BoxMutator,
325 BoxMutatorOnce,
326 BoxStatefulMutator,
327
328 FnMutStatefulMutatorOps,
329 FnMutatorOnceOps,
330 // Extension traits
331 FnMutatorOps,
332 // Core traits
333 Mutator,
334 MutatorOnce,
335 RcConditionalMutator,
336 RcConditionalStatefulMutator,
337 // Rc-based (shared single-threaded ownership)
338 RcMutator,
339 RcStatefulMutator,
340
341 StatefulMutator,
342};
343
344// ---- Predicate Types (Fn(&T) -> bool) ----
345pub use predicates::{
346 // Arc-based (shared multi-threaded ownership)
347 ArcPredicate,
348
349 // Box-based (single ownership)
350 BoxPredicate,
351
352 // Extension traits
353 FnPredicateOps,
354 // Core traits
355 Predicate,
356
357 // Rc-based (shared single-threaded ownership)
358 RcPredicate,
359};
360
361// ---- BiPredicate Types (Fn(&T, &U) -> bool) ----
362pub use predicates::{
363 // Arc-based (shared multi-threaded ownership)
364 ArcBiPredicate,
365
366 // Core traits
367 BiPredicate,
368
369 // Box-based (single ownership)
370 BoxBiPredicate,
371
372 // Extension traits
373 FnBiPredicateOps,
374 // Rc-based (shared single-threaded ownership)
375 RcBiPredicate,
376};
377
378// ---- Supplier Types (Fn() -> R) ----
379pub use suppliers::{
380 ArcStatefulSupplier,
381
382 // Arc-based (shared multi-threaded ownership)
383 ArcSupplier,
384 BoxStatefulSupplier,
385
386 // Box-based (single ownership)
387 BoxSupplier,
388 BoxSupplierOnce,
389 // Extension traits
390 FnStatefulSupplierOps,
391 RcStatefulSupplier,
392
393 // Rc-based (shared single-threaded ownership)
394 RcSupplier,
395 StatefulSupplier,
396
397 // Core traits
398 Supplier,
399 SupplierOnce,
400};
401
402// ---- Task Types (fallible actions and computations) ----
403pub use tasks::{
404 ArcCallable,
405 ArcCallableWith,
406 ArcRunnable,
407 ArcRunnableWith,
408 BoxCallable,
409 BoxCallableOnce,
410 BoxCallableWith,
411 BoxRunnable,
412 BoxRunnableOnce,
413 BoxRunnableWith,
414 Callable,
415 CallableOnce,
416 CallableWith,
417 RcCallable,
418 RcCallableWith,
419 RcRunnable,
420 RcRunnableWith,
421 Runnable,
422 RunnableOnce,
423 RunnableWith,
424};
425
426// ---- Comparator Types (Fn(&T, &T) -> Ordering) ----
427pub use comparator::{
428 // Arc-based (shared multi-threaded ownership)
429 ArcComparator,
430
431 // Box-based (single ownership)
432 BoxComparator,
433
434 // Core traits
435 Comparator,
436
437 // Extension traits
438 FnComparatorOps,
439 // Rc-based (shared single-threaded ownership)
440 RcComparator,
441};
442
443// ---- Tester Types (FnMut() -> bool) ----
444pub use tester::{
445 // Arc-based (shared multi-threaded ownership)
446 ArcTester,
447
448 // Box-based (single ownership)
449 BoxTester,
450
451 // Extension traits
452 FnTesterOps,
453 // Rc-based (shared single-threaded ownership)
454 RcTester,
455
456 // Core traits
457 Tester,
458};