1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! End-state targets: a minimum level required at one tick.
use crate;
use crate::;
/// A minimum level the timeline must have at one tick, for example the battery reserve
/// required at the end of a sol so the rover survives the night.
///
/// Unlike the [`Bounds`](crate::Bounds), which hold at every tick, a target holds at `at`
/// only: activities after `at` may draw the level lower again. The level at `at` includes
/// every impact at `at`. Targets take part in every check, so
/// [`Timeline::first_violation`](crate::Timeline::first_violation), [`Plan::fits`](crate::Plan::fits)
/// and [`Plan::earliest_start`](crate::Plan::earliest_start) reject schedules that miss one; a
/// miss is reported as [`Bound::BelowTarget`](crate::Bound::BelowTarget).
///
/// # Examples
///
/// ```
/// use resource_timeline::{ActivityId, Bound, Bounds, Impact, Target, Timeline};
///
/// // A sol lasts 100 ticks; 40 units must be left at its end.
/// let mut battery = Timeline::depletable(0, 100, Bounds::new(10, 100)?, 8)?;
/// battery.add_target(Target { at: 100, min: 40 })?;
/// battery.add(ActivityId(1), Impact::Rate { start: 20, end: 90, per_tick: -1 })?;
///
/// let violation = battery.first_violation()?.expect("the end-of-sol reserve is missed");
/// assert_eq!((violation.at, violation.level), (100, 30));
/// assert_eq!(violation.bound, Bound::BelowTarget(40));
/// # Ok::<(), resource_timeline::Error>(())
/// ```