Skip to content

Commit bc4b203

Browse files
committed
fmt
1 parent 8b99c21 commit bc4b203

File tree

13 files changed

+151
-67
lines changed

13 files changed

+151
-67
lines changed

examples/complex_macros.rs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ fn main() {
5050
users: vec![
5151
User {
5252
id: 1,
53-
profile: Some(Profile { display_name: "Ada".into(), age: 31 }),
53+
profile: Some(Profile {
54+
display_name: "Ada".into(),
55+
age: 31,
56+
}),
5457
tags: vec!["admin".into(), "founder".into()],
5558
},
5659
User {
@@ -59,7 +62,10 @@ fn main() {
5962
tags: vec!["guest".into()],
6063
},
6164
],
62-
settings: Some(Settings { theme: "dark".into(), db: Some(DbConfig(5432, "postgres://localhost".into())) }),
65+
settings: Some(Settings {
66+
theme: "dark".into(),
67+
db: Some(DbConfig(5432, "postgres://localhost".into())),
68+
}),
6369
connection: Connection::Connecting(42),
6470
name: "MegaApp".into(),
6571
};
@@ -69,7 +75,10 @@ fn main() {
6975
.compose(KeyPaths::failable_readable(|v: &Vec<User>| v.first()))
7076
.compose(User::profile_fr())
7177
.compose(Profile::display_name_r());
72-
println!("first_user_profile_name = {:?}", first_user_profile_name.get(&app));
78+
println!(
79+
"first_user_profile_name = {:?}",
80+
first_user_profile_name.get(&app)
81+
);
7382

7483
// 2) Mutate nested Option chain via failable writable
7584
let settings_fw = App::settings_fw();
@@ -82,7 +91,10 @@ fn main() {
8291
}
8392
}
8493
}
85-
println!("db after bump = {:?}", app.settings.as_ref().and_then(|s| s.db.as_ref()));
94+
println!(
95+
"db after bump = {:?}",
96+
app.settings.as_ref().and_then(|s| s.db.as_ref())
97+
);
8698

8799
// 3) Compose writable + enum case (prism) to mutate only when connected
88100
app.connection = Connection::Connected("10.0.0.1".into());
@@ -103,21 +115,30 @@ fn main() {
103115
// 5) Iterate immutably and mutably via derived vec keypaths
104116
let users_r = App::users_r();
105117
if let Some(mut iter) = users_r.iter::<User>(&app) {
106-
if let Some(u0) = iter.next() { println!("first user id = {}", u0.id); }
118+
if let Some(u0) = iter.next() {
119+
println!("first user id = {}", u0.id);
120+
}
107121
}
108122
let users_w = App::users_w();
109123
if let Some(iter) = users_w.iter_mut::<User>(&mut app) {
110-
for u in iter { u.tags.push("seen".into()); }
124+
for u in iter {
125+
u.tags.push("seen".into());
126+
}
111127
}
112128
println!("users after tag = {:?}", app.users);
113129

114130
// 6) Compose across many levels: first user -> profile -> age (if present) and increment
115131
let first_user_fr = KeyPaths::failable_readable(|v: &Vec<User>| v.first());
116132
let profile_fr = User::profile_fr();
117133
let age_w = Profile::age_w();
118-
if let Some(u0) = first_user_fr.get(&app.users) { // borrow helper
134+
if let Some(u0) = first_user_fr.get(&app.users) {
135+
// borrow helper
119136
let mut app_ref = &mut app.users[0];
120-
if let Some(p) = profile_fr.get_mut(&mut app_ref) { if let Some(age) = age_w.get_mut(p) { *age += 1; } }
137+
if let Some(p) = profile_fr.get_mut(&mut app_ref) {
138+
if let Some(age) = age_w.get_mut(p) {
139+
*age += 1;
140+
}
141+
}
121142
}
122143
println!("first user after bday = {:?}", app.users.first());
123144

@@ -127,15 +148,19 @@ fn main() {
127148
println!("embedded = {:?}", new_conn);
128149

129150
// 8) Additional enum with casepaths: Status
130-
let mut st = Status::Active(User { id: 99, profile: None, tags: vec![] });
151+
let mut st = Status::Active(User {
152+
id: 99,
153+
profile: None,
154+
tags: vec![],
155+
});
131156
let st_active = Status::active_case_r();
132157
let st_active_name = st_active.compose(User::id_r());
133158
println!("status active user id = {:?}", st_active_name.get(&st));
134159

135160
let st_pending = Status::pending_case_w();
136161
st = Status::Pending(5);
137-
if let Some(v) = st_pending.get_mut(&mut st) { *v += 1; }
162+
if let Some(v) = st_pending.get_mut(&mut st) {
163+
*v += 1;
164+
}
138165
println!("status after pending increment = {:?}", st);
139166
}
140-
141-

examples/compose_macros.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ fn main() {
4040

4141
// Demonstrate writable/failable-writable compose
4242
let mut city2 = City {
43-
garage: Some(Garage { car: Some(Car { engine: Some(Engine { horsepower: 100 }) }) }),
43+
garage: Some(Garage {
44+
car: Some(Car {
45+
engine: Some(Engine { horsepower: 100 }),
46+
}),
47+
}),
4448
};
4549

4650
let garage_fw = City::garage_fw();
@@ -60,5 +64,3 @@ fn main() {
6064

6165
println!("Updated city2 = {:?}", city2);
6266
}
63-
64-

examples/enum_casepaths_macros.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,29 @@ enum Status {
1414
}
1515

1616
fn main() {
17-
let status = Status::Active(User { id: 1, name: "Ada".into() });
17+
let status = Status::Active(User {
18+
id: 1,
19+
name: "Ada".into(),
20+
});
1821

1922
let kp_active = Status::active_case_r();
2023
let active_name = Status::active_case_r().compose(User::name_r());
2124
println!("Active name = {:?}", active_name.get(&status));
2225

23-
let mut status2 = Status::Active(User { id: 2, name: "Bob".into() });
26+
let mut status2 = Status::Active(User {
27+
id: 2,
28+
name: "Bob".into(),
29+
});
2430
let kp_active_w = Status::active_case_w();
2531
if let Some(user) = kp_active_w.get_mut(&mut status2) {
2632
user.name.push_str("_edited");
2733
}
2834
println!("Status2 = {:?}", status2);
2935

3036
// Embedding via readable enum
31-
let embedded = kp_active.embed(User { id: 3, name: "Cleo".into() });
37+
let embedded = kp_active.embed(User {
38+
id: 3,
39+
name: "Cleo".into(),
40+
});
3241
println!("Embedded = {:?}", embedded);
3342
}
34-
35-

examples/enum_keypath_macros.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ fn main() {
2424
let user_name_kp = User::name_r();
2525
let user_id_kp = User::id_r();
2626

27-
let user = User { id: 7, name: "Ada".into() };
27+
let user = User {
28+
id: 7,
29+
name: "Ada".into(),
30+
};
2831
println!("user.name via kp = {:?}", user_name_kp.get(&user));
2932
println!("user.id via kp = {:?}", user_id_kp.get(&user));
3033

@@ -44,7 +47,10 @@ fn main() {
4447
_ => None,
4548
});
4649

47-
let status = Status::Active(User { id: 42, name: "Grace".into() });
50+
let status = Status::Active(User {
51+
id: 42,
52+
name: "Grace".into(),
53+
});
4854

4955
if let Some(u) = status_active_user.get(&status) {
5056
println!("Extracted user: {:?}", u);
@@ -59,7 +65,10 @@ fn main() {
5965

6066
println!("Active user name = {:?}", active_user_name.get(&status));
6167

62-
let embedded = status_active_user.embed(User { id: 99, name: "Lin".into() });
68+
let embedded = status_active_user.embed(User {
69+
id: 99,
70+
name: "Lin".into(),
71+
});
6372
println!("Embedded back: {:?}", embedded);
6473

6574
let greeting = SomeOtherStatus::Active("Hello".to_string());
@@ -72,5 +81,3 @@ fn main() {
7281
println!("Status::Inactive: {:?}", x);
7382
}
7483
}
75-
76-

examples/failable_macros.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,3 @@ fn main() {
6666
println!("No garage to mutate");
6767
}
6868
}
69-
70-

examples/failable_writable_macros.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,3 @@ fn main() {
6363
}
6464
println!("City with missing path unchanged = {:?}", city_missing);
6565
}
66-
67-

examples/iters_macros.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,3 @@ fn main() {
2929

3030
println!("{:?}", g.cars);
3131
}
32-
33-

examples/prism_compose_macros.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,24 @@ struct ABox {
2828
fn main() {
2929
let mut a_box = ABox {
3030
name: String::from("A box"),
31-
size: Size { width: 10, height: 20 },
31+
size: Size {
32+
width: 10,
33+
height: 20,
34+
},
3235
color: Color::Other(RGBU8(10, 20, 30)),
3336
};
3437

3538
let color_kp = ABox::color_w();
3639
let case_path = KeyPaths::writable_enum(
3740
|v| Color::Other(v),
38-
|c: &Color| match c { Color::Other(rgb) => Some(rgb), _ => None },
39-
|c: &mut Color| match c { Color::Other(rgb) => Some(rgb), _ => None },
41+
|c: &Color| match c {
42+
Color::Other(rgb) => Some(rgb),
43+
_ => None,
44+
},
45+
|c: &mut Color| match c {
46+
Color::Other(rgb) => Some(rgb),
47+
_ => None,
48+
},
4049
);
4150

4251
let color_rgb_kp = color_kp.compose(case_path);
@@ -46,5 +55,3 @@ fn main() {
4655

4756
println!("{:?}", a_box);
4857
}
49-
50-

examples/prism_macros.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,4 @@
4040
// println!("{:?}", p);
4141
// }
4242

43-
fn main() {
44-
45-
}
43+
fn main() {}

examples/surprise.rs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ fn main() {
5050
users: vec![
5151
User {
5252
id: 1,
53-
profile: Some(Profile { display_name: "Ada".into(), age: 31 }),
53+
profile: Some(Profile {
54+
display_name: "Ada".into(),
55+
age: 31,
56+
}),
5457
tags: vec!["admin".into(), "founder".into()],
5558
},
5659
User {
@@ -59,7 +62,10 @@ fn main() {
5962
tags: vec!["guest".into()],
6063
},
6164
],
62-
settings: Some(Settings { theme: "dark".into(), db: Some(DbConfig(5432, "postgres://localhost".into())) }),
65+
settings: Some(Settings {
66+
theme: "dark".into(),
67+
db: Some(DbConfig(5432, "postgres://localhost".into())),
68+
}),
6369
connection: Connection::Connecting(42),
6470
name: "MegaApp".into(),
6571
};
@@ -69,7 +75,10 @@ fn main() {
6975
.compose(KeyPaths::failable_readable(|v: &Vec<User>| v.first()))
7076
.compose(User::profile_fr())
7177
.compose(Profile::display_name_r());
72-
println!("first_user_profile_name = {:?}", first_user_profile_name.get(&app));
78+
println!(
79+
"first_user_profile_name = {:?}",
80+
first_user_profile_name.get(&app)
81+
);
7382

7483
// 2) Mutate nested Option chain via failable writable
7584
let settings_fw = App::settings_fw();
@@ -82,7 +91,10 @@ fn main() {
8291
}
8392
}
8493
}
85-
println!("db after bump = {:?}", app.settings.as_ref().and_then(|s| s.db.as_ref()));
94+
println!(
95+
"db after bump = {:?}",
96+
app.settings.as_ref().and_then(|s| s.db.as_ref())
97+
);
8698

8799
// 3) Compose writable + enum case (prism) to mutate only when connected
88100
app.connection = Connection::Connected("10.0.0.1".into());
@@ -103,21 +115,30 @@ fn main() {
103115
// 5) Iterate immutably and mutably via derived vec keypaths
104116
let users_r = App::users_r();
105117
if let Some(mut iter) = users_r.iter::<User>(&app) {
106-
if let Some(u0) = iter.next() { println!("first user id = {}", u0.id); }
118+
if let Some(u0) = iter.next() {
119+
println!("first user id = {}", u0.id);
120+
}
107121
}
108122
let users_w = App::users_w();
109123
if let Some(iter) = users_w.iter_mut::<User>(&mut app) {
110-
for u in iter { u.tags.push("seen".into()); }
124+
for u in iter {
125+
u.tags.push("seen".into());
126+
}
111127
}
112128
println!("users after tag = {:?}", app.users);
113129

114130
// 6) Compose across many levels: first user -> profile -> age (if present) and increment
115131
let first_user_fr = KeyPaths::failable_readable(|v: &Vec<User>| v.first());
116132
let profile_fr = User::profile_fr();
117133
let age_w = Profile::age_w();
118-
if let Some(u0) = first_user_fr.get(&app.users) { // borrow helper
134+
if let Some(u0) = first_user_fr.get(&app.users) {
135+
// borrow helper
119136
let mut app_ref = &mut app.users[0];
120-
if let Some(p) = profile_fr.get_mut(&mut app_ref) { if let Some(age) = age_w.get_mut(p) { *age += 1; } }
137+
if let Some(p) = profile_fr.get_mut(&mut app_ref) {
138+
if let Some(age) = age_w.get_mut(p) {
139+
*age += 1;
140+
}
141+
}
121142
}
122143
println!("first user after bday = {:?}", app.users.first());
123144

@@ -127,15 +148,19 @@ fn main() {
127148
println!("embedded = {:?}", new_conn);
128149

129150
// 8) Additional enum with casepaths: Status
130-
let mut st = Status::Active(User { id: 99, profile: None, tags: vec![] });
151+
let mut st = Status::Active(User {
152+
id: 99,
153+
profile: None,
154+
tags: vec![],
155+
});
131156
let st_active = Status::active_case_r();
132157
let st_active_name = st_active.compose(User::id_r());
133158
println!("status active user id = {:?}", st_active_name.get(&st));
134159

135160
let st_pending = Status::pending_case_w();
136161
st = Status::Pending(5);
137-
if let Some(v) = st_pending.get_mut(&mut st) { *v += 1; }
162+
if let Some(v) = st_pending.get_mut(&mut st) {
163+
*v += 1;
164+
}
138165
println!("status after pending increment = {:?}", st);
139166
}
140-
141-

0 commit comments

Comments
 (0)