Skip to main content

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