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