Skip to content

Commit cc45404

Browse files
committed
casepath level wip
1 parent 4ee7841 commit cc45404

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

examples/prism_macros.rs

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
1-
use key_paths_core::KeyPaths;
2-
use key_paths_derive::Casepaths;
1+
// use key_paths_core::KeyPaths;
2+
// use key_paths_derive::Casepaths;
33

4-
#[derive(Debug, Casepaths)]
5-
enum Payment {
6-
Cash { amount: u32 },
7-
Card { number: String, cvv: String },
8-
}
4+
// #[derive(Debug, Casepaths)]
5+
// enum Payment {
6+
// Cash { amount: u32 },
7+
// Card { number: String, cvv: String },
8+
// }
99

10-
fn main() {
11-
// let kp = KeyPaths::Prism {
12-
// extract: Rc::new(|p: &Payment| match p {
13-
// Payment::Cash { amount } => Some(amount),
14-
// _ => None,
15-
// }),
16-
// // embed: Rc::new(|v| Payment::Cash { amount: v }),
17-
// embed: Rc::new(|v| Payment::Cash { amount: v.clone() }),
18-
// };
19-
let kp = KeyPaths::writable_enum(
20-
|v| Payment::Cash { amount: v },
21-
|p: &Payment| match p {
22-
Payment::Cash { amount } => Some(amount),
23-
_ => None,
24-
},
25-
|p: &mut Payment| match p {
26-
Payment::Cash { amount } => Some(amount),
27-
_ => None,
28-
},
29-
);
10+
// fn main() {
11+
// // let kp = KeyPaths::Prism {
12+
// // extract: Rc::new(|p: &Payment| match p {
13+
// // Payment::Cash { amount } => Some(amount),
14+
// // _ => None,
15+
// // }),
16+
// // // embed: Rc::new(|v| Payment::Cash { amount: v }),
17+
// // embed: Rc::new(|v| Payment::Cash { amount: v.clone() }),
18+
// // };
19+
// let kp = KeyPaths::writable_enum(
20+
// |v| Payment::Cash { amount: v },
21+
// |p: &Payment| match p {
22+
// Payment::Cash { amount } => Some(amount),
23+
// _ => None,
24+
// },
25+
// |p: &mut Payment| match p {
26+
// Payment::Cash { amount } => Some(amount),
27+
// _ => None,
28+
// },
29+
// );
30+
31+
// let mut p = Payment::Cash { amount: 10 };
3032

31-
let mut p = Payment::Cash { amount: 10 };
33+
// println!("{:?}", p);
3234

33-
println!("{:?}", p);
35+
// if let Some(v) = kp.get_mut(&mut p) {
36+
// *v = 34
37+
// }
38+
// // kp.get_mut(&mut p); // this will return none as kp is readable
3439

35-
if let Some(v) = kp.get_mut(&mut p) {
36-
*v = 34
37-
}
38-
// kp.get_mut(&mut p); // this will return none as kp is readable
40+
// println!("{:?}", p);
41+
// }
3942

40-
println!("{:?}", p);
41-
}
43+
fn main() {
44+
45+
}

0 commit comments

Comments
 (0)