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