Skip to content

Commit 74df398

Browse files
committed
fmt
1 parent 75271ee commit 74df398

File tree

4 files changed

+27
-35
lines changed

4 files changed

+27
-35
lines changed

examples/enum_keypath_example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn main() {
4040
}
4141

4242
// let cp4 = enum_keypath!(SomeOtherStatus::Inactive);
43-
let cp4 = KeyPaths::readable_enum(|u: ()| { SomeOtherStatus::Inactive }, |u| None);
43+
let cp4 = KeyPaths::readable_enum(|u: ()| SomeOtherStatus::Inactive, |u| None);
4444
if let Some(x) = cp4.get(&SomeOtherStatus::Inactive) {
4545
println!("Inactive: {:?}", x);
4646
}

examples/prism.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ enum Payment {
55
Card { number: String, cvv: String },
66
}
77

8-
9-
108
fn main() {
119
// let kp = KeyPaths::Prism {
1210
// extract: Rc::new(|p: &Payment| match p {
@@ -26,7 +24,6 @@ fn main() {
2624
Payment::Cash { amount } => Some(amount),
2725
_ => None,
2826
},
29-
3027
);
3128

3229
let mut p = Payment::Cash { amount: 10 };
@@ -39,4 +36,4 @@ fn main() {
3936
// kp.get_mut(&mut p); // this will return none as kp is readable
4037

4138
println!("{:?}", p);
42-
}
39+
}

examples/prism_compose.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,21 @@ struct Rectangle {
3030
name: String,
3131
}
3232

33-
34-
3533
fn main() {
3634
let mut a_box = ABox {
3735
name: String::from("A box"),
3836
size: Size {
3937
width: 10,
4038
height: 20,
4139
},
42-
color: Color::Other(
43-
RGBU8(10, 20, 30)
44-
),
40+
color: Color::Other(RGBU8(10, 20, 30)),
4541
};
4642

47-
let color_kp: KeyPaths<ABox, Color> = KeyPaths::failable_writable(|x: &mut ABox| Some(&mut x.color));
48-
49-
43+
let color_kp: KeyPaths<ABox, Color> =
44+
KeyPaths::failable_writable(|x: &mut ABox| Some(&mut x.color));
45+
5046
let case_path = KeyPaths::writable_enum(
51-
{
52-
|v| Color::Other(v)
53-
},
47+
{ |v| Color::Other(v) },
5448
|p: &Color| match p {
5549
Color::Other(rgb) => Some(rgb),
5650
_ => None,
@@ -59,22 +53,20 @@ fn main() {
5953
Color::Other(rgb) => Some(rgb),
6054
_ => None,
6155
},
62-
6356
);
64-
65-
// let's compose color with rgb
66-
57+
58+
// let's compose color with rgb
59+
6760
println!("{:?}", a_box);
6861
let color_rgb_kp = color_kp.compose(case_path);
6962
if let Some(value) = color_rgb_kp.get_mut(&mut a_box) {
7063
*value = RGBU8(0, 0, 0);
7164
}
7265

7366
println!("{:?}", a_box);
74-
7567
}
7668

7769
/*
7870
ABox { name: "A box", size: Size { width: 10, height: 20 }, color: Other(RGBU8(10, 20, 30)) }
7971
ABox { name: "A box", size: Size { width: 10, height: 20 }, color: Other(RGBU8(0, 0, 0)) }
80-
*/
72+
*/

key-paths-core/src/lib.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ impl<Root, Value> KeyPaths<Root, Value> {
107107
}
108108
}
109109

110-
111110
/// Iter over immutable references if `Value: IntoIterator`
112111
pub fn iter<'a, T>(&'a self, root: &'a Root) -> Option<<&'a Value as IntoIterator>::IntoIter>
113112
where
@@ -210,9 +209,9 @@ where
210209
// // // extract_mut(r).and_then(|m| f2(m))
211210
// // // let x = f2(m);
212211
// // extract_mut(r).and_then(|a| f2(a))
213-
// //
212+
// //
214213
// // }
215-
// //
214+
// //
216215
// // ))
217216
// // FailableWritable(Rc::new(move |r| extract_mut(r).and_then(|a| f2(a))))
218217
// // FailableWritable(Rc::new(move |r: &mut Root| {
@@ -221,7 +220,7 @@ where
221220
// // None => None,
222221
// // }
223222
// // }) as Rc<dyn for<'a> Fn(&'a mut Root) -> Option<&'a mut Value>>)
224-
//
223+
//
225224
// FailableWritable(Rc::new(move |r: &mut Root| {
226225
// // First extract the intermediate value using extract_mut
227226
// extract_mut(r).and_then(|intermediate| {
@@ -250,12 +249,12 @@ where
250249
// }))
251250
// }
252251

253-
/* (FailableWritable(f2), WritableEnum { extract_mut, .. }) => {
254-
FailableWritable(Rc::new(move |r: &mut Root| {
255-
extract_mut(r).and_then(|intermediate_mid| f2(intermediate_mid))
256-
}))
257-
}
258-
*/
252+
/* (FailableWritable(f2), WritableEnum { extract_mut, .. }) => {
253+
FailableWritable(Rc::new(move |r: &mut Root| {
254+
extract_mut(r).and_then(|intermediate_mid| f2(intermediate_mid))
255+
}))
256+
}
257+
*/
259258
// (FailableWritable(f2), WritableEnum { extract_mut, .. }) => {
260259
// // Here's the fix: f2 must be a function that operates on a Mid and returns a Value
261260
// // It is already of this type since the 'mid' KeyPaths is KeyPaths<Mid, Value>
@@ -272,8 +271,13 @@ where
272271
// f2(mid_ref)
273272
// }))
274273
// }
275-
276-
(FailableWritable(f_root_mid), WritableEnum { extract_mut: exm_mid_val, .. }) => {
274+
(
275+
FailableWritable(f_root_mid),
276+
WritableEnum {
277+
extract_mut: exm_mid_val,
278+
..
279+
},
280+
) => {
277281
FailableWritable(Rc::new(move |r: &mut Root| {
278282
// First, apply the function that operates on Root.
279283
// This will give us `Option<&mut Mid>`.
@@ -285,7 +289,6 @@ where
285289
}))
286290
}
287291

288-
289292
(WritableEnum { extract_mut, .. }, FailableWritable(f2)) => {
290293
FailableWritable(Rc::new(move |r| extract_mut(r).and_then(|m| f2(m))))
291294
}

0 commit comments

Comments
 (0)