prism3_function/
lib.rs

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