Struct aligner::TimeSpan
[−]
[src]
pub struct TimeSpan { /* fields omitted */ }
Represents a time span from "start" (included) to "end" (excluded).
The constructors will ensure "start <= end", this condition will hold at any given time.
Methods
impl TimeSpan
[src]
fn new(start: TimePoint, end: TimePoint) -> TimeSpan
Create a new TimeSpan with start
and end
.
Examples
use aligner::{TimeSpan, TimePoint}; let t0 = TimePoint::from(0); let t10 = TimePoint::from(10); let ts = TimeSpan::new(t0, t10);
Panics
This function asserts that start
is less or equal end
.
use aligner::{TimeSpan, TimePoint}; let t0 = TimePoint::from(0); let t10 = TimePoint::from(10); // this will case a panic let ts = TimeSpan::new(t10, t0);
fn new_safe(start: TimePoint, end: TimePoint) -> TimeSpan
Create a new TimeSpan with start
and end
. This function will not
panic on end < start
, but
swap the values before calling TimeSpan::new()
.
Examples
use aligner::{TimeSpan, TimePoint}; let t0 = TimePoint::from(0); let t10 = TimePoint::from(10); let ts = TimeSpan::new_safe(t10, t0); assert!(ts.start() == t0 && ts.end() == t10);
fn new_copy_with_end(self, new_end: TimePoint) -> TimeSpan
fn len(self) -> TimeDelta
Returns the length of the TimeSpan
.
len()
is zero, if and only if start
is end
.
fn is_empty(self) -> bool
Returns true if start == end
.
fn start(self) -> TimePoint
Returns the start point of the TimeSpan
.
fn end(self) -> TimePoint
Returns the end point of the TimeSpan
.
fn contains(self, other: TimeSpan) -> bool
fn fast_distance_to(self, other: TimeSpan) -> TimeDelta
Returns the smallest difference between two TimeSpan
s.
use aligner::{TimeSpan, TimePoint, TimeDelta}; let p = TimePoint::from(0); let d = TimeDelta::one(); let ts1 = TimeSpan::new(p, p + 10 * d); let ts4 = TimeSpan::new(p + 20 * d, p + 100 * d); assert!(TimeSpan::fast_distance_to(ts1, ts1) == 0 * d); assert!(TimeSpan::fast_distance_to(ts1, ts4) == 10 * d); assert!(TimeSpan::fast_distance_to(ts4, ts1) == 10 * d); assert!(TimeSpan::fast_distance_to(ts4, ts4) == 0 * d);
fn get_overlapping_length(self, other: TimeSpan) -> TimeDelta
Returns the smallest difference between two TimeSpan
s.
fn cmp_start(self, other: TimeSpan) -> Ordering
Compares two TimeSpan
s by their start timepoint.
fn cmp_end(self, other: TimeSpan) -> Ordering
Compares two TimeSpan
s by their end timepoint.
Trait Implementations
impl Copy for TimeSpan
[src]
impl Clone for TimeSpan
[src]
fn clone(&self) -> TimeSpan
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 TimeSpan
[src]
impl PartialEq for TimeSpan
[src]
fn eq(&self, __arg_0: &TimeSpan) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &TimeSpan) -> bool
This method tests for !=
.
impl Eq for TimeSpan
[src]
impl Hash for TimeSpan
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0
Feeds a slice of this type into the state provided.