Skip to main content

transformer_blanket_impl_demo/
transformer_blanket_impl_demo.rs

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