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

Creates a new empty timeline.

The newly created timeline has no borders and only a single interval (-∞, ∞).

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.

Provides the count of borders between intervals.

Provides the count of intervals.

Note that this is always border_count() + 1.

Returns an iterator over the borders.

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);

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).

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 the other are inserted into the current one.

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, or None if interested from the beginning of all times.
  • end: Just like start, just from the other side.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Timeline

Formats the value using the given formatter.

impl Default for Timeline

Returns the "default value" for a type. Read more

impl Eq for Timeline

impl PartialEq for Timeline

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Serialize for Timeline

Serialize this value into the given Serde serializer. Read more