transformer_blanket_impl_demo/
transformer_blanket_impl_demo.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025.
4 *    3-Prism Co. Ltd.
5 *
6 *    All rights reserved.
7 *
8 ******************************************************************************/
9
10//! Demonstrates blanket implementations for Fn -> Transformer
11
12use prism3_function::Transformer;
13
14fn main() {
15    println!("=== Testing Fn -> Transformer ===");
16    test_transformer();
17}
18
19fn test_transformer() {
20    // Test function pointer
21    fn double(x: i32) -> i32 {
22        x * 2
23    }
24    assert_eq!(double.apply(21), 42);
25    println!("✓ Function pointer test passed: double.apply(21) = 42");
26
27    // Test closure
28    let triple = |x: i32| x * 3;
29    assert_eq!(triple.apply(14), 42);
30    println!("✓ Closure test passed: triple.apply(14) = 42");
31
32    // Test conversion to BoxTransformer
33    let quad = |x: i32| x * 4;
34    let boxed = Transformer::into_box(quad);
35    assert_eq!(boxed.apply(10), 40);
36    println!("✓ into_box() test passed");
37
38    // Test conversion to RcTransformer
39    let times_five = |x: i32| x * 5;
40    let rc = Transformer::into_rc(times_five);
41    assert_eq!(rc.apply(8), 40);
42    println!("✓ into_rc() test passed");
43
44    // Test conversion to ArcTransformer
45    let times_six = |x: i32| x * 6;
46    let arc = Transformer::into_arc(times_six);
47    assert_eq!(arc.apply(7), 42);
48    println!("✓ into_arc() test passed");
49}