1use qubit_common::{
18 Pair,
19 Triple,
20};
21
22fn main() {
23 println!("=== Pair Demo ===\n");
24
25 let pair1 = Pair::new("name", "Alice");
27 println!("pair1 (using new): {}", pair1);
28
29 let mut pair2 = Pair {
31 first: 1,
32 second: 100,
33 };
34 println!("pair2 (using struct literal): {}", pair2);
35
36 pair2.first = 42;
38 pair2.second = 200;
39 println!("pair2 (after modification): {}", pair2);
40
41 let pair3 = Pair::new(10, 20);
43 println!("pair3: {}", pair3);
44 println!(" first: {}, second: {}", pair3.first(), pair3.second());
45
46 let pair4 = pair3.map_first(|x| x * 2).map_second(|x| x * 3);
48 println!("pair4 (after mapping): {}", pair4);
49
50 let pair5 = Pair::new("key", 123);
52 let swapped = pair5.swap();
53 println!("pair5: {}, swapped: {}", pair5, swapped);
54
55 let (f, s) = pair5.into_tuple();
57 println!("Converted to tuple: ({}, {})", f, s);
58
59 println!("\n=== Triple Demo ===\n");
60
61 let triple1 = Triple::new("Alice", 30, true);
63 println!("triple1 (using new): {}", triple1);
64
65 let mut triple2 = Triple {
67 first: 1,
68 second: 2,
69 third: 3,
70 };
71 println!("triple2 (using struct literal): {}", triple2);
72
73 triple2.first = 10;
75 triple2.second = 20;
76 triple2.third = 30;
77 println!("triple2 (after modification): {}", triple2);
78
79 let triple3 = Triple::new(100, 200, 300);
81 println!("triple3: {}", triple3);
82 println!(
83 " first: {}, second: {}, third: {}",
84 triple3.first(),
85 triple3.second(),
86 triple3.third()
87 );
88
89 let triple4 = triple3
91 .map_first(|x| x / 10)
92 .map_second(|x| x / 10)
93 .map_third(|x| x / 10);
94 println!("triple4 (after mapping): {}", triple4);
95
96 let (f, s, t) = triple4.into_tuple();
98 println!("Converted to tuple: ({}, {}, {})", f, s, t);
99
100 println!("\n=== Advanced Usage ===\n");
101
102 let config = Pair {
104 first: "database_url",
105 second: "postgresql://localhost/mydb",
106 };
107 println!("Config: {}", config);
108
109 let record = Triple {
111 first: "user_001",
112 second: "Alice",
113 third: 25,
114 };
115 println!(
116 "User Record: ID={}, Name={}, Age={}",
117 record.first, record.second, record.third
118 );
119
120 let nested = Pair {
122 first: Pair::new(1, 2),
123 second: Triple::new(3, 4, 5),
124 };
125 println!(
126 "Nested: pair=({}, {}), triple=({}, {}, {})",
127 nested.first.first,
128 nested.first.second,
129 nested.second.first,
130 nested.second.second,
131 nested.second.third
132 );
133}