Skip to content

Commit cd1bb4a

Browse files
committed
change landing page example to rust
1 parent b2b6700 commit cd1bb4a

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

content/en/_index.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,23 @@ Model your planning problems with an expressive, business-object oriented syntax
2727
<span class="terminal-btn close"></span>
2828
<span class="terminal-btn minimize"></span>
2929
<span class="terminal-btn maximize"></span>
30-
<span class="terminal-title">constraints.py</span>
30+
<span class="terminal-title">constraints.rs</span>
3131
</div>
3232
<div class="terminal-body">
3333

34-
```python
35-
def desired_day_for_employee(constraint_factory: ConstraintFactory):
36-
return (
37-
constraint_factory.for_each(Shift)
38-
.join(
39-
Employee,
40-
Joiners.equal(lambda shift: shift.employee, lambda employee: employee),
41-
)
42-
.flatten_last(lambda employee: employee.desired_dates)
43-
.filter(lambda shift, desired_date: shift.is_overlapping_with_date(desired_date))
44-
.reward(
45-
HardSoftDecimalScore.ONE_SOFT,
46-
lambda shift, desired_date: shift.get_overlapping_duration_in_minutes(desired_date),
47-
)
48-
.as_constraint("Desired day for employee")
34+
```rust
35+
// =========================================================================
36+
// HARD: One Shift Per Day
37+
// =========================================================================
38+
let one_per_day = factory
39+
.clone()
40+
.for_each_unique_pair(
41+
|s: &EmployeeSchedule| s.shifts.as_slice(),
42+
joiner::equal(|shift: &Shift| (shift.employee_idx, shift.date())),
4943
)
44+
.filter(|a: &Shift, b: &Shift| a.employee_idx.is_some() && b.employee_idx.is_some())
45+
.penalize(HardSoftDecimalScore::ONE_HARD)
46+
.as_constraint("One shift per day");
5047
```
5148

5249
</div>

0 commit comments

Comments
 (0)