pub struct TimeSpan { /* private fields */ }Expand description
Represents a time span from “start” (included) to “end” (excluded).
The constructors will ensure “start <= end”, this condition will hold at any given time.
Implementations§
Source§impl TimeSpan
impl TimeSpan
Sourcepub fn new(start: TimePoint, end: TimePoint) -> TimeSpan
pub 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);Sourcepub fn new_safe(start: TimePoint, end: TimePoint) -> TimeSpan
pub 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);Sourcepub fn new_copy_with_end(self, new_end: TimePoint) -> TimeSpan
pub fn new_copy_with_end(self, new_end: TimePoint) -> TimeSpan
Sourcepub fn len(self) -> TimeDelta
pub fn len(self) -> TimeDelta
Returns the length of the TimeSpan.
len() is zero, if and only if start is end.
Sourcepub fn fast_distance_to(self, other: TimeSpan) -> TimeDelta
pub fn fast_distance_to(self, other: TimeSpan) -> TimeDelta
Returns the smallest difference between two TimeSpans.
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);Sourcepub fn get_overlapping_length(self, other: TimeSpan) -> TimeDelta
pub fn get_overlapping_length(self, other: TimeSpan) -> TimeDelta
Returns the smallest difference between two TimeSpans.
Trait Implementations§
impl Copy for TimeSpan
impl Eq for TimeSpan
impl StructuralPartialEq for TimeSpan
Auto Trait Implementations§
impl Freeze for TimeSpan
impl RefUnwindSafe for TimeSpan
impl Send for TimeSpan
impl Sync for TimeSpan
impl Unpin for TimeSpan
impl UnwindSafe for TimeSpan
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more