Struct libdata::time::Timeline
[−]
pub struct Timeline { /* fields omitted */ }
A timeline.
A timeline splits the time continuum into intervals. There are borders (the times when one interval ends and another begins) and intervals. Note that there's one more of the intervals than the borders and the first and last intervals are infinite (eg. the first one is from -∞, the last one to ∞).
Note
This structure doesn't provide the usual methods like len
or into_iter
. The reason is, as
it can be iterated in two different ways, such methods would be ambiguous and therefore
confusing. It has borders
and intervals
instead.
Methods
impl Timeline
fn new() -> Self
Creates a new empty timeline.
The newly created timeline has no borders and only a single interval (-∞, ∞).
fn from_borders(borders: Vec<SystemTime>) -> Self
Creates a timeline from a vec of borders.
Parameters
borders
: A sorted array of (unique) borders between the intervals in the timeline to be.
Panics
The consructor panics if the provided list of borders is not sorted or if there are duplicates.
fn border_count(&self) -> usize
Provides the count of borders between intervals.
fn interval_count(&self) -> usize
Provides the count of intervals.
Note that this is always border_count()
+ 1.
fn borders(&self) -> Iter<SystemTime>
Returns an iterator over the borders.
fn intervals(&self) -> IntervalIter
Returns an iterator over the intervals.
The first interval starts in -∞ (specified by None
) and the last one ends with ∞ (also
specified by None
). If the interval has a neighbor, it has Some(border)
towards the
neighbor.
Examples
let empty = Timeline::new(); let intervals = empty.intervals().collect::<Vec<_>>(); assert_eq!(vec![(None, None)], intervals);
let mut timeline = Timeline::new(); let time = SystemTime::now(); timeline.split(time); let intervals = timeline.intervals().collect::<Vec<_>>(); assert_eq!(vec![(None, Some(time)), (Some(time), None)], intervals);
fn split(&mut self, time: SystemTime)
Splits the timeline at the given time.
Makes sure the timeline has two intervals separated by the given time. If the timeline is already split at that time, nothing happens.
Parameters
time
: The new border to insert into the timeline (or to ignore, if there's a same one already).
fn combine(&mut self, other: Timeline)
Combines two timelines together.
The modified timeline will be split on the borders of both previous timelines. This is probably best shown in an image:
<------|------|---->
<---|--|--|-------->
<---|--|--|---|---->
In other words, it is equivalent to splitting one slice by all the borders of the other (but with less overhead).
Parameters
other
: The other timeline to combine with. All the borders from theother
are inserted into the current one.
fn clip(&mut self, start: Option<SystemTime>, end: Option<SystemTime>)
Clips the timeline into the given interval.
The start and end parameters specify the interesting interval of time. Everything to the left and right to the interval is thrown away and merged into the infinite ends of the timeline.
<---|----|---|--|---->
↑ ↑
======================
<-----|--|---|------->
Parameters
start
: The start of the range of interest, orNone
if interested from the beginning of all times.end
: Just likestart
, just from the other side.
fn place(&self, start: SystemTime, end: SystemTime) -> usize
Returns the index of interval the provided thing falls into.
It chooses the interval of the timeline the provided slice can be best said it belongs to. To handle a very finely sliced time line, the slice is approximated by a single point in the middle and an interval that includes the point is found.
Parameters
start
: Start of the interval.end
: End of the interval.
Panics
If the interval is inverted.
fn is_unsplit(&self) -> bool
Determines if the timeline is not split.
An unsplit timeline is one that has only a single interval (-∞, ∞). It is returned by
the new
.
Trait Implementations
impl Clone for Timeline
fn clone(&self) -> Timeline
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Debug for Timeline
impl Default for Timeline
impl Eq for Timeline
impl PartialEq for Timeline
fn eq(&self, __arg_0: &Timeline) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Timeline) -> bool
This method tests for !=
.